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

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

Issue 209853010: [ABANDONED] Enable V8 Promises (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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 f373fa9f3e1347a6ea148a86c18c3db1f09632ff..f409a8bc8091c4358cf314db6f56a29201e88e42 100644
--- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h
+++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h
@@ -41,25 +41,13 @@ public:
template <typename T>
void resolve(T value)
{
- if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped())
- return;
- m_state = Resolving;
- NewScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8(value));
- if (!executionContext()->activeDOMObjectsAreSuspended())
- resolveOrRejectImmediately(&m_timer);
+ resolveOrReject(value, Resolving);
}
template <typename T>
void reject(T value)
{
- if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped())
- return;
- m_state = Rejecting;
- NewScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8(value));
- if (!executionContext()->activeDOMObjectsAreSuspended())
- resolveOrRejectImmediately(&m_timer);
+ resolveOrReject(value, Rejecting);
}
// Note that an empty ScriptPromise will be returned after resolve or
@@ -99,12 +87,33 @@ private:
ASSERT(m_scriptState);
return v8ArrayNoInline(value, m_scriptState->isolate());
}
- v8::Handle<v8::Value> toV8(ScriptValue value)
+ v8::Handle<v8::Value> toV8(ScriptValue value) { return value.v8Value(); }
+ v8::Handle<v8::Value> toV8(v8::Handle<v8::Value> value) { return value; }
+
+ template <typename T>
+ void resolveOrReject(T value, ResolutionState newState)
{
- return value.v8Value();
+ if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped())
+ return;
+ m_state = newState;
+ // Retain this object until it is actually resolved or rejected.
+ // deref will be called in resolveOrRejectImmediately.
+ ref();
yhirano 2014/04/15 08:45:06 I don't like the manual ref counting, but I couldn
+
+ bool isInContext = m_scriptState->isolate()->InContext();
+ NewScriptState::Scope scope(m_scriptState.get());
+ m_value.set(m_scriptState->isolate(), toV8(value));
+ if (!executionContext()->activeDOMObjectsAreSuspended()) {
+ if (isInContext) {
+ resolveOrRejectImmediately();
+ } else {
+ m_timer.startOneShot(0, FROM_HERE);
+ }
+ }
}
- void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*);
+ void resolveOrRejectImmediately();
+ void onTimerFired(Timer<ScriptPromiseResolverWithContext>*);
void clear();
ResolutionState m_state;

Powered by Google App Engine
This is Rietveld 408576698