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

Unified Diff: sky/engine/bindings-dart/core/dart/DartScriptPromiseResolver.h

Issue 875013003: Import Dart bindings as of Blink r188698. This merely copies the files over and does not attach any… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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: sky/engine/bindings-dart/core/dart/DartScriptPromiseResolver.h
diff --git a/sky/engine/bindings/core/v8/ScriptPromiseResolver.h b/sky/engine/bindings-dart/core/dart/DartScriptPromiseResolver.h
similarity index 51%
copy from sky/engine/bindings/core/v8/ScriptPromiseResolver.h
copy to sky/engine/bindings-dart/core/dart/DartScriptPromiseResolver.h
index 2c63def4a60e406259c787d3a98aa61f9dc79a98..2d873003814c7a48dc7a77f4069b8c2c1d52571b 100644
--- a/sky/engine/bindings/core/v8/ScriptPromiseResolver.h
+++ b/sky/engine/bindings-dart/core/dart/DartScriptPromiseResolver.h
@@ -2,41 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISERESOLVER_H_
-#define SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISERESOLVER_H_
-
-#include "sky/engine/bindings/core/v8/ScopedPersistent.h"
-#include "sky/engine/bindings/core/v8/ScriptPromise.h"
-#include "sky/engine/bindings/core/v8/ScriptState.h"
-#include "sky/engine/bindings/core/v8/V8Binding.h"
-#include "sky/engine/core/dom/ActiveDOMObject.h"
-#include "sky/engine/core/dom/ExecutionContext.h"
-#include "sky/engine/platform/Timer.h"
-#include "sky/engine/wtf/RefCounted.h"
-#include "v8/include/v8.h"
+#ifndef DartScriptPromiseResolver_h
+#define DartScriptPromiseResolver_h
+
+#include "bindings/common/ScriptPromiseResolver.h"
+#include "bindings/common/ScriptState.h"
+#include "bindings/core/dart/DartDOMException.h"
+#include "bindings/core/dart/DartDOMWrapper.h"
+#include "bindings/core/dart/DartScriptPromise.h"
+#include "bindings/core/dart/DartUtilities.h"
+#include "bindings/core/v8/V8ScriptState.h"
+#include "core/dom/ActiveDOMObject.h"
+#include "core/dom/ExecutionContext.h"
+#include "platform/Timer.h"
+#include "wtf/RefCounted.h"
+#include <dart_api.h>
namespace blink {
-// 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);
+class ScriptPromiseResolver;
+
+class DartScriptPromiseResolver : public AbstractScriptPromiseResolver {
+ WTF_MAKE_NONCOPYABLE(DartScriptPromiseResolver);
public:
- static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState)
+ static PassOwnPtr<DartScriptPromiseResolver> create(DartScriptState* scriptState, ScriptPromiseResolver* owner)
{
- RefPtr<ScriptPromiseResolver> resolver = adoptRef(new ScriptPromiseResolver(scriptState));
- resolver->suspendIfNeeded();
- return resolver.release();
+ return adoptPtr(new DartScriptPromiseResolver(scriptState, owner));
}
- virtual ~ScriptPromiseResolver()
+ virtual ~DartScriptPromiseResolver()
{
// This assertion fails if:
// - promise() is called at least once and
@@ -45,16 +40,24 @@ public:
ASSERT(m_state == ResolvedOrRejected || !m_isPromiseCalled);
}
+ ExecutionContext* executionContext() { return m_scriptState->executionContext(); }
+
+#define DECLARE_RESOLUTION_METHODS(type) \
+ void resolve(type); \
+ void reject(type);
+PROMISE_RESOLUTION_TYPES_LIST(DECLARE_RESOLUTION_METHODS);
+#undef DECLARE_RESOLUTION_METHODS
+
// Anything that can be passed to toV8Value can be passed to this function.
template <typename T>
- void resolve(T value)
+ void resolveInternal(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)
+ void rejectInternal(T value)
{
resolveOrReject(value, Rejecting);
}
@@ -66,20 +69,22 @@ public:
// Note that an empty ScriptPromise will be returned after resolve or
// reject is called.
- ScriptPromise promise()
+ PassRefPtr<AbstractScriptPromise> promise()
{
#if ENABLE(ASSERT)
m_isPromiseCalled = true;
#endif
- return m_resolver.promise();
+ ASSERT(m_completer);
+ Dart_Handle future = Dart_GetField(m_completer, Dart_NewStringFromCString("future"));
+ return DartScriptPromise::create(m_scriptState.get(), future);
}
ScriptState* scriptState() const { return m_scriptState.get(); }
// ActiveDOMObject implementation.
- virtual void suspend() override;
- virtual void resume() override;
- virtual void stop() override;
+ virtual void suspend();
+ virtual void resume();
+ virtual void stop();
// Once this function is called this resolver stays alive while the
// promise is pending and the associated ExecutionContext isn't stopped.
@@ -88,10 +93,9 @@ public:
protected:
// You need to call suspendIfNeeded after the construction because
// this is an ActiveDOMObject.
- explicit ScriptPromiseResolver(ScriptState*);
+ explicit DartScriptPromiseResolver(DartScriptState*, ScriptPromiseResolver*);
private:
- typedef ScriptPromise::InternalResolver Resolver;
enum ResolutionState {
Pending,
Resolving,
@@ -103,12 +107,6 @@ private:
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)
{
@@ -118,24 +116,33 @@ private:
m_state = newState;
// Retain this object until it is actually resolved or rejected.
// |deref| will be called in |clear|.
- ref();
+ m_owner->ref();
+
+ DartIsolateScope scope(m_scriptState->isolate());
+ DartApiScope apiScope;
+ // FIXMEDART: Remove this.
+ V8ScriptState::Scope v8Scope(m_scriptState->v8ScriptState());
- ScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8Value(value));
+ // FIXMEDART: Should be able to get DartDOMData from a DartScriptState instead of TLS.
+ Dart_Handle v = DartValueTraits<T>::toDartValue(value, DartDOMData::current());
+ m_value = Dart_NewPersistentHandle(v);
if (!executionContext()->activeDOMObjectsAreSuspended())
resolveOrRejectImmediately();
}
void resolveOrRejectImmediately();
- void onTimerFired(Timer<ScriptPromiseResolver>*);
+ void onTimerFired(Timer<DartScriptPromiseResolver>*);
void clear();
ResolutionState m_state;
- const RefPtr<ScriptState> m_scriptState;
+ const RefPtr<DartScriptState> m_scriptState;
+ ScriptPromiseResolver* m_owner;
LifetimeMode m_mode;
- Timer<ScriptPromiseResolver> m_timer;
- Resolver m_resolver;
- ScopedPersistent<v8::Value> m_value;
+ Timer<DartScriptPromiseResolver> m_timer;
+
+ Dart_PersistentHandle m_completer;
+ Dart_PersistentHandle m_value;
+
#if ENABLE(ASSERT)
// True if promise() is called.
bool m_isPromiseCalled;
@@ -144,4 +151,4 @@ private:
} // namespace blink
-#endif // SKY_ENGINE_BINDINGS_CORE_V8_SCRIPTPROMISERESOLVER_H_
+#endif // #ifndef DartScriptPromiseResolver_h

Powered by Google App Engine
This is Rietveld 408576698