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

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

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.h
diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.h b/Source/bindings/v8/ScriptPromiseResolverWithContext.h
index 0ccf94e1c1d77195839cb79d9341d22c808fd0b2..d569326245345b021b39ef43ac4dd98c74ed3fb2 100644
--- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h
+++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h
@@ -27,7 +27,7 @@ namespace WebCore {
// ExecutionContext state. When the ExecutionContext is suspended,
// resolve or reject will be delayed. When it is stopped, resolve or reject
// will be ignored.
-class ScriptPromiseResolverWithContext : public ActiveDOMObject, public RefCounted<ScriptPromiseResolverWithContext> {
+class ScriptPromiseResolverWithContext FINAL : public ActiveDOMObject, public RefCounted<ScriptPromiseResolverWithContext> {
WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext);
public:
@@ -38,6 +38,8 @@ public:
return resolver.release();
}
+ virtual ~ScriptPromiseResolverWithContext();
+
// Anything that can be passed to toV8Value can be passed to this function.
template <typename T>
void resolve(T value)
@@ -68,8 +70,19 @@ public:
virtual void resume() OVERRIDE;
virtual void stop() OVERRIDE;
-protected:
- explicit ScriptPromiseResolverWithContext(ScriptState*);
+ // This function registers |value| to the associated Promise as a hidden
haraken 2014/06/13 14:23:31 This function registers a wrapper of |value| to th
+ // property. As a result, |value| will be kept alive until one of the
+ // following events happens:
+ // - the Promise is resolved
+ // - the Promise is rejected
+ // - the Promise is disposed by the GC
+ // - this object is destructed
+ template<typename T>
+ void keepObjectWhilePending(const T& value)
+ {
+ ScriptState::Scope scope(m_scriptState.get());
haraken 2014/06/13 14:23:31 Probably it's better to move this ScriptState::Sco
+ keepObjectWhilePendingInternal(toV8Value(value));
+ }
private:
enum ResolutionState {
@@ -79,6 +92,8 @@ private:
ResolvedOrRejected,
};
+ explicit ScriptPromiseResolverWithContext(ScriptState*);
+
template<typename T>
v8::Handle<v8::Value> toV8Value(const T& value)
{
@@ -105,6 +120,9 @@ private:
void onTimerFired(Timer<ScriptPromiseResolverWithContext>*);
void clear();
+ void keepObjectWhilePendingInternal(v8::Handle<v8::Value>);
+ void unregisterKeptObject();
haraken 2014/06/13 14:23:31 keepObjectWhilePending => registerPendingObject ke
+
ResolutionState m_state;
const RefPtr<ScriptState> m_scriptState;
Timer<ScriptPromiseResolverWithContext> m_timer;

Powered by Google App Engine
This is Rietveld 408576698