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

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

Issue 351423002: Moved files under Source/bindings/v8 to Source/bindings/core/v8. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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
« no previous file with comments | « Source/bindings/v8/ScriptPromise.cpp ('k') | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptPromiseResolver.h
diff --git a/Source/bindings/v8/ScriptPromiseResolver.h b/Source/bindings/v8/ScriptPromiseResolver.h
deleted file mode 100644
index c2ad9e22e4a62fe5633ab9973ebefdfc614d0d76..0000000000000000000000000000000000000000
--- a/Source/bindings/v8/ScriptPromiseResolver.h
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ScriptPromiseResolver_h
-#define ScriptPromiseResolver_h
-
-#include "bindings/v8/ScopedPersistent.h"
-#include "bindings/v8/ScriptPromise.h"
-#include "bindings/v8/ScriptState.h"
-#include "bindings/v8/V8Binding.h"
-#include "core/dom/ActiveDOMObject.h"
-#include "core/dom/ExecutionContext.h"
-#include "platform/Timer.h"
-#include "wtf/RefCounted.h"
-#include "wtf/Vector.h"
-#include <v8.h>
-
-namespace WebCore {
-
-// This class wraps v8::Promise::Resolver and provides the following
-// functionalities.
-// - A ScriptPromiseResolver retains a ScriptState. A caller
-// can call resolve or reject from outside of a V8 context.
-// - This class is an ActiveDOMObject and keeps track of the associated
-// ExecutionContext state. When the ExecutionContext is suspended,
-// resolve or reject will be delayed. When it is stopped, resolve or reject
-// will be ignored.
-class ScriptPromiseResolver : public ActiveDOMObject, public RefCounted<ScriptPromiseResolver> {
- WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver);
-
-public:
- static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState)
- {
- RefPtr<ScriptPromiseResolver> resolver = adoptRef(new ScriptPromiseResolver(scriptState));
- resolver->suspendIfNeeded();
- return resolver.release();
- }
-
- virtual ~ScriptPromiseResolver()
- {
- // This assertion fails if:
- // - promise() is called at least once and
- // - this resolver is destructed before it is resolved, rejected or
- // the associated ExecutionContext is stopped.
- ASSERT(m_state == ResolvedOrRejected || !m_isPromiseCalled);
- }
-
- // Anything that can be passed to toV8Value can be passed to this function.
- template <typename T>
- void resolve(T value)
- {
- resolveOrReject(value, Resolving);
- }
-
- // Anything that can be passed to toV8Value can be passed to this function.
- template <typename T>
- void reject(T value)
- {
- resolveOrReject(value, Rejecting);
- }
-
- ScriptState* scriptState() { return m_scriptState.get(); }
-
- // Note that an empty ScriptPromise will be returned after resolve or
- // reject is called.
- ScriptPromise promise()
- {
-#if ASSERT_ENABLED
- m_isPromiseCalled = true;
-#endif
- return m_resolver.promise();
- }
-
- ScriptState* scriptState() const { return m_scriptState.get(); }
-
- // ActiveDOMObject implementation.
- virtual void suspend() OVERRIDE;
- virtual void resume() OVERRIDE;
- virtual void stop() OVERRIDE;
-
- // Once this function is called this resolver stays alive while the
- // promise is pending and the associated ExecutionContext isn't stopped.
- void keepAliveWhilePending();
-
-protected:
- // You need to call suspendIfNeeded after the construction because
- // this is an ActiveDOMObject.
- explicit ScriptPromiseResolver(ScriptState*);
-
-private:
- typedef ScriptPromise::InternalResolver Resolver;
- enum ResolutionState {
- Pending,
- Resolving,
- Rejecting,
- ResolvedOrRejected,
- };
- enum LifetimeMode {
- Default,
- KeepAliveWhilePending,
- };
-
- template<typename T>
- v8::Handle<v8::Value> toV8Value(const T& value)
- {
- return V8ValueTraits<T>::toV8Value(value, m_scriptState->context()->Global(), m_scriptState->isolate());
- }
-
- template <typename T>
- void resolveOrReject(T value, ResolutionState newState)
- {
- if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped())
- return;
- ASSERT(newState == Resolving || newState == Rejecting);
- m_state = newState;
- // Retain this object until it is actually resolved or rejected.
- // |deref| will be called in |clear|.
- ref();
-
- ScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8Value(value));
- if (!executionContext()->activeDOMObjectsAreSuspended())
- resolveOrRejectImmediately();
- }
-
- void resolveOrRejectImmediately();
- void onTimerFired(Timer<ScriptPromiseResolver>*);
- void clear();
-
- ResolutionState m_state;
- const RefPtr<ScriptState> m_scriptState;
- LifetimeMode m_mode;
- Timer<ScriptPromiseResolver> m_timer;
- Resolver m_resolver;
- ScopedPersistent<v8::Value> m_value;
-#if ASSERT_ENABLED
- // True if promise() is called.
- bool m_isPromiseCalled;
-#endif
-};
-
-} // namespace WebCore
-
-#endif // #ifndef ScriptPromiseResolver_h
« no previous file with comments | « Source/bindings/v8/ScriptPromise.cpp ('k') | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698