Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: Source/core/events/PromiseRejectionEvent.cpp

Issue 1181353005: Return null when no promise/reason is given in PromiseRejectionEvent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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();
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_reason.isEmpty() || !m_scriptState || !m_scriptState->contextIsValid() || m_scriptState->world().worldId() != state->world().worldId())
47 return ScriptValue(state, v8::Null(state->isolate()));
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
OLDNEW
« no previous file with comments | « Source/core/events/PromiseRejectionEvent.h ('k') | Source/core/events/PromiseRejectionEvent.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698