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 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 PromiseRejectionEvent::PromiseRejectionEvent() | 11 PromiseRejectionEvent::PromiseRejectionEvent() |
| 12 { | 12 { |
| 13 } | 13 } |
| 14 | 14 |
| 15 PromiseRejectionEvent::PromiseRejectionEvent(const AtomicString& type, const Pro miseRejectionEventInit& initializer) | 15 PromiseRejectionEvent::PromiseRejectionEvent(const AtomicString& type, const Pro miseRejectionEventInit& initializer) |
| 16 : Event(type, initializer) | 16 : Event(type, initializer) |
| 17 , m_reason(initializer.reason()) | |
| 18 { | 17 { |
| 19 if (initializer.hasPromise()) | 18 if (initializer.hasPromise()) { |
| 20 m_promise = initializer.promise(); | 19 m_promise.set(initializer.promise().isolate(), initializer.promise().v8V alue()); |
| 20 m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise); | |
| 21 } | |
| 22 if (initializer.hasReason()) { | |
| 23 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); | |
| 24 m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason); | |
| 25 } | |
| 21 } | 26 } |
| 22 | 27 |
| 23 PromiseRejectionEvent::~PromiseRejectionEvent() | 28 PromiseRejectionEvent::~PromiseRejectionEvent() |
| 24 { | 29 { |
| 25 } | 30 } |
| 26 | 31 |
| 32 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const | |
| 33 { | |
| 34 v8::Local<v8::Value> value = m_promise.newLocal(state->isolate()); | |
|
yurys
2015/06/18 13:03:21
Should there be a check that the promise is not pa
jochen (gone - plz use gerrit)
2015/06/18 13:25:23
if you manage to get the event in a different cont
| |
| 35 return ScriptPromise(state, value); | |
| 36 } | |
| 37 | |
| 38 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const | |
| 39 { | |
| 40 v8::Local<v8::Value> value = m_reason.newLocal(state->isolate()); | |
| 41 return ScriptValue(state, value); | |
| 42 } | |
| 27 | 43 |
| 28 const AtomicString& PromiseRejectionEvent::interfaceName() const | 44 const AtomicString& PromiseRejectionEvent::interfaceName() const |
| 29 { | 45 { |
| 30 return EventNames::PromiseRejectionEvent; | 46 return EventNames::PromiseRejectionEvent; |
| 31 } | 47 } |
| 32 | 48 |
| 33 DEFINE_TRACE(PromiseRejectionEvent) | 49 DEFINE_TRACE(PromiseRejectionEvent) |
| 34 { | 50 { |
| 35 Event::trace(visitor); | 51 Event::trace(visitor); |
| 36 } | 52 } |
| 37 | 53 |
| 54 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise RejectionEvent>& data) | |
| 55 { | |
| 56 data.GetParameter()->m_promise.clear(); | |
| 57 } | |
| 58 | |
| 59 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR ejectionEvent>& data) | |
| 60 { | |
| 61 data.GetParameter()->m_reason.clear(); | |
| 62 } | |
| 63 | |
| 38 } // namespace blink | 64 } // namespace blink |
| OLD | NEW |