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(ScriptState* state, const AtomicStr ing& type, const PromiseRejectionEventInit& initializer) |
| 16 : Event(type, initializer) | 16 : Event(type, initializer) |
| 17 , m_scriptState(state) | |
| 17 { | 18 { |
| 18 if (initializer.hasPromise()) { | 19 if (initializer.hasPromise()) { |
| 19 m_promise.set(initializer.promise().isolate(), initializer.promise().v8V alue()); | 20 m_promise.set(initializer.promise().isolate(), initializer.promise().v8V alue()); |
| 20 m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise); | 21 m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise); |
| 21 } | 22 } |
| 22 if (initializer.hasReason()) { | 23 if (initializer.hasReason()) { |
| 23 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); | 24 m_reason.set(initializer.reason().isolate(), initializer.reason().v8Valu e()); |
| 24 m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason); | 25 m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 | 28 |
| 28 PromiseRejectionEvent::~PromiseRejectionEvent() | 29 PromiseRejectionEvent::~PromiseRejectionEvent() |
| 29 { | 30 { |
| 30 } | 31 } |
| 31 | 32 |
| 32 ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const | 33 ScriptPromise PromiseRejectionEvent::promise() const |
| 33 { | 34 { |
| 34 v8::Local<v8::Value> value = m_promise.newLocal(state->isolate()); | 35 if (!m_scriptState || !m_scriptState->contextIsValid()) |
|
haraken
2015/06/19 11:38:03
When is it possible that m_scriptState becomes 0?
jochen (gone - plz use gerrit)
2015/06/19 12:06:21
The ctor that doesn't take parameters doesn't init
| |
| 35 return ScriptPromise(state, value); | 36 return ScriptPromise(); |
| 37 return ScriptPromise(m_scriptState.get(), m_promise.newLocal(m_scriptState-> isolate())); | |
| 36 } | 38 } |
| 37 | 39 |
| 38 ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const | 40 ScriptValue PromiseRejectionEvent::reason() const |
| 39 { | 41 { |
| 40 v8::Local<v8::Value> value = m_reason.newLocal(state->isolate()); | 42 if (!m_scriptState || !m_scriptState->contextIsValid()) |
| 41 return ScriptValue(state, value); | 43 return ScriptValue(); |
| 44 return ScriptValue(m_scriptState.get(), m_reason.newLocal(m_scriptState->iso late())); | |
| 42 } | 45 } |
| 43 | 46 |
| 44 const AtomicString& PromiseRejectionEvent::interfaceName() const | 47 const AtomicString& PromiseRejectionEvent::interfaceName() const |
| 45 { | 48 { |
| 46 return EventNames::PromiseRejectionEvent; | 49 return EventNames::PromiseRejectionEvent; |
| 47 } | 50 } |
| 48 | 51 |
| 49 DEFINE_TRACE(PromiseRejectionEvent) | 52 DEFINE_TRACE(PromiseRejectionEvent) |
| 50 { | 53 { |
| 51 Event::trace(visitor); | 54 Event::trace(visitor); |
| 52 } | 55 } |
| 53 | 56 |
| 54 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise RejectionEvent>& data) | 57 void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<Promise RejectionEvent>& data) |
| 55 { | 58 { |
| 56 data.GetParameter()->m_promise.clear(); | 59 data.GetParameter()->m_promise.clear(); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR ejectionEvent>& data) | 62 void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseR ejectionEvent>& data) |
|
haraken
2015/06/19 11:38:03
(Nit: It's not really nice we have to write V8 thi
| |
| 60 { | 63 { |
| 61 data.GetParameter()->m_reason.clear(); | 64 data.GetParameter()->m_reason.clear(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 } // namespace blink | 67 } // namespace blink |
| OLD | NEW |