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

Unified Diff: Source/core/events/PromiseRejectionEvent.cpp

Issue 1189513004: Fix memory leaks caused by PromiseRejectionEvents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/events/PromiseRejectionEvent.h ('k') | Source/core/events/PromiseRejectionEvent.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/events/PromiseRejectionEvent.cpp
diff --git a/Source/core/events/PromiseRejectionEvent.cpp b/Source/core/events/PromiseRejectionEvent.cpp
index 17bb08b177e75014bdce963d50a2217400728d25..2a4eb14da3e3e3f7db1e1889e116c6543a59e2ba 100644
--- a/Source/core/events/PromiseRejectionEvent.cpp
+++ b/Source/core/events/PromiseRejectionEvent.cpp
@@ -14,16 +14,32 @@ PromiseRejectionEvent::PromiseRejectionEvent()
PromiseRejectionEvent::PromiseRejectionEvent(const AtomicString& type, const PromiseRejectionEventInit& initializer)
: Event(type, initializer)
- , m_reason(initializer.reason())
{
- if (initializer.hasPromise())
- m_promise = initializer.promise();
+ if (initializer.hasPromise()) {
+ m_promise.set(initializer.promise().isolate(), initializer.promise().v8Value());
+ m_promise.setWeak(this, &PromiseRejectionEvent::didCollectPromise);
+ }
+ if (initializer.hasReason()) {
+ m_reason.set(initializer.reason().isolate(), initializer.reason().v8Value());
+ m_reason.setWeak(this, &PromiseRejectionEvent::didCollectReason);
+ }
}
PromiseRejectionEvent::~PromiseRejectionEvent()
{
}
+ScriptPromise PromiseRejectionEvent::promise(ScriptState* state) const
+{
+ 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
+ return ScriptPromise(state, value);
+}
+
+ScriptValue PromiseRejectionEvent::reason(ScriptState* state) const
+{
+ v8::Local<v8::Value> value = m_reason.newLocal(state->isolate());
+ return ScriptValue(state, value);
+}
const AtomicString& PromiseRejectionEvent::interfaceName() const
{
@@ -35,4 +51,14 @@ DEFINE_TRACE(PromiseRejectionEvent)
Event::trace(visitor);
}
+void PromiseRejectionEvent::didCollectPromise(const v8::WeakCallbackInfo<PromiseRejectionEvent>& data)
+{
+ data.GetParameter()->m_promise.clear();
+}
+
+void PromiseRejectionEvent::didCollectReason(const v8::WeakCallbackInfo<PromiseRejectionEvent>& data)
+{
+ data.GetParameter()->m_reason.clear();
+}
+
} // namespace blink
« 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