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

Unified Diff: Source/bindings/v8/ScriptPromiseResolverWithContext.cpp

Issue 311733004: Introduce KeepAliveWhilePending to ScriptPromiseResolverWithContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@refactor-webmidi-initialization
Patch Set: Created 6 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
Index: Source/bindings/v8/ScriptPromiseResolverWithContext.cpp
diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp b/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp
index 1a39cac07223f4c777f9d4df80e891041609d0fa..bc4ba6d7da416643bf6a74480b35d8dd22e56db2 100644
--- a/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp
+++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.cpp
@@ -9,6 +9,10 @@
namespace WebCore {
+namespace {
+const char hiddenPropertyName[] = "blink::keepObjectWhilePending";
+} // namespace
+
ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState* scriptState)
: ActiveDOMObject(scriptState->executionContext())
, m_state(Pending)
@@ -18,6 +22,16 @@ ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState*
{
}
+ScriptPromiseResolverWithContext::~ScriptPromiseResolverWithContext()
+{
+ if (m_state != ResolvedOrRejected) {
+ unregisterKeptObject();
+ ScriptState::Scope scope(m_scriptState.get());
+ reject(v8::Exception::Error(v8::String::NewFromUtf8(m_scriptState->isolate(),
+ "ScriptPromiseResolverWithContext is destructed without resolve / reject")));
+ }
+}
+
void ScriptPromiseResolverWithContext::suspend()
{
m_timer.stop();
@@ -63,6 +77,7 @@ void ScriptPromiseResolverWithContext::resolveOrRejectImmediately()
void ScriptPromiseResolverWithContext::clear()
{
+ unregisterKeptObject();
ResolutionState state = m_state;
m_state = ResolvedOrRejected;
m_resolver.clear();
@@ -74,4 +89,31 @@ void ScriptPromiseResolverWithContext::clear()
// |this| may be deleted here.
}
+void ScriptPromiseResolverWithContext::keepObjectWhilePendingInternal(v8::Handle<v8::Value> value)
+{
+ v8::HandleScope handleScope(m_scriptState->isolate());
+ if (!m_resolver)
+ return;
+ ScriptPromise promise = this->promise();
+ if (promise.isEmpty())
+ return;
+ v8::Local<v8::Promise> v8Promise = promise.v8Value().As<v8::Promise>();
+ v8::Local<v8::String> name = v8::String::NewFromUtf8(m_scriptState->isolate(), hiddenPropertyName);
+ ASSERT(v8Promise->GetHiddenValue(name).IsEmpty());
+ v8Promise->SetHiddenValue(name, value);
haraken 2014/06/13 05:03:51 Consider using helper methods in V8HiddenValue.h i
yhirano 2014/06/13 11:15:22 Done.
+}
+
+void ScriptPromiseResolverWithContext::unregisterKeptObject()
+{
+ v8::HandleScope handleScope(m_scriptState->isolate());
+ if (!m_resolver)
+ return;
+ ScriptPromise promise = this->promise();
+ if (promise.isEmpty())
+ return;
+ v8::Local<v8::Promise> v8Promise = promise.v8Value().As<v8::Promise>();
+ v8::Local<v8::String> name = v8::String::NewFromUtf8(m_scriptState->isolate(), hiddenPropertyName);
+ v8Promise->DeleteHiddenValue(name);
yhirano 2014/06/12 11:02:51 Rafael, I heard that deleting a property is genera
rafaelw 2014/06/13 02:36:17 Haraken is probably more authoritative on this tha
haraken 2014/06/13 03:36:53 Agreed, I don't think deleting a hidden property a
yhirano 2014/06/13 04:19:30 Then is it better to have another boolean member v
yhirano 2014/06/13 04:19:30 Thanks!
haraken 2014/06/13 05:03:51 Only if this code is really performance-sensitive
+}
+
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.h ('k') | Source/modules/crypto/CrossThreadCryptoResult.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698