Index: Source/core/dom/Future.h |
diff --git a/Source/core/dom/Future.h b/Source/core/dom/Future.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2369a2fca64820499e8610652e99b842ca6193c6 |
--- /dev/null |
+++ b/Source/core/dom/Future.h |
@@ -0,0 +1,137 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#ifndef Future_h |
+#define Future_h |
+ |
+#include "bindings/v8/ScriptValue.h" |
+#include "core/dom/ActiveDOMObject.h" |
+#include "core/dom/AnyCallback.h" |
+#include "core/dom/FutureInit.h" |
+#include "core/dom/FutureResolver.h" |
+#include "wtf/PassRefPtr.h" |
+#include "wtf/RefCounted.h" |
+#include "wtf/RefPtr.h" |
+#include "wtf/Vector.h" |
+ |
+namespace WebCore { |
+ |
+// Needed due to circular dependency. |
+class AnyCallback; |
+class FutureInit; |
+ |
+class Future : public RefCounted<Future>, public ActiveDOMObject { |
+public: |
+ enum State { |
+ Pending, |
+ Accepted, |
+ Rejected |
+ }; |
+ |
+ static PassRefPtr<Future> createAndRunInit(PassRefPtr<FutureInit>); |
+ |
+ static PassRefPtr<Future> accept(const ScriptValue&); |
+ static PassRefPtr<Future> resolve(const ScriptValue&); |
+ static PassRefPtr<Future> reject(const ScriptValue&); |
+ |
+ static PassRefPtr<Future> anyof(Vector<ScriptValue>&); |
+ static PassRefPtr<Future> every(Vector<ScriptValue>&); |
+ static PassRefPtr<Future> some(Vector<ScriptValue>&); |
+ |
+ PassRefPtr<Future> then(PassRefPtr<AnyCallback>, PassRefPtr<AnyCallback>); |
+ void done(PassRefPtr<AnyCallback>, PassRefPtr<AnyCallback>); |
+ |
+ void then(PassRefPtr<Future>); |
+ |
+ void setResolver(PassRefPtr<FutureResolver> resolver) { m_resolver = resolver; } |
+ PassRefPtr<FutureResolver> getResolver() { return m_resolver; } |
+ |
+ // Methods for m_resolver to modify the associated Future instance. |
+ |
+ void setState(State state) { m_state = state; } |
+ void setResult(const ScriptValue& result) { m_result = result; } |
+ |
+ void processAcceptCallbacks(const ScriptValue&); |
+ void queueProcessAcceptCallbacksTask(const ScriptValue&); |
+ void processRejectCallbacks(const ScriptValue&); |
+ void queueProcessRejectCallbacksTask(const ScriptValue&); |
+ |
+ // For RefCounted<Future>. |
+ virtual ~Future(); |
+ |
+private: |
+ class FutureCallback : public RefCounted<FutureCallback> { |
+ public: |
+ enum Algorithm { |
+ NoAlgorithm, |
+ WrapperAlgorithm, |
+ AcceptAlgorithm, |
+ ResolveAlgorithm, |
+ RejectAlgorithm |
+ }; |
+ |
+ static PassRefPtr<FutureCallback> create(Algorithm algorithm, PassRefPtr<FutureResolver> resolver, PassRefPtr<AnyCallback> callback) |
+ { |
+ return adoptRef(new FutureCallback(algorithm, resolver, callback)); |
+ } |
+ |
+ void invoke(const ScriptValue&); |
+ |
+ private: |
+ FutureCallback(Algorithm algorithm, PassRefPtr<FutureResolver> resolver, PassRefPtr<AnyCallback> callback) |
+ : m_algorithm(algorithm) |
+ , m_resolver(resolver) |
+ , m_callback(callback) |
+ { |
+ } |
+ |
+ Algorithm m_algorithm; |
+ RefPtr<FutureResolver> m_resolver; |
+ RefPtr<AnyCallback> m_callback; |
+ }; |
+ |
+ static PassRefPtr<Future> create(); |
+ |
+ explicit Future(ScriptExecutionContext*); |
+ |
+ void appendCallbacks(PassRefPtr<FutureCallback> acceptCallback, PassRefPtr<FutureCallback> rejectCallback); |
+ |
+ Vector<RefPtr<FutureCallback> > m_acceptCallbacks; |
+ Vector<RefPtr<FutureCallback> > m_rejectCallbacks; |
+ State m_state; |
+ ScriptValue m_result; |
abarth-chromium
2013/05/23 17:56:47
We should talk more about the general approach. U
|
+ |
+ // The associated FutureResolver instance. |
+ RefPtr<FutureResolver> m_resolver; |
+}; |
+ |
+} // namespace WebCore |
+ |
+#endif // Future_h |