#ifndef ScriptPromiseResolver_h
#define ScriptPromiseResolver_h
#include "bindings/v8/DOMWrapperWorld.h"
#include "bindings/v8/ScopedPersistent.h"
#include "bindings/v8/ScriptObject.h"
#include "bindings/v8/ScriptPromise.h"
#include "bindings/v8/ScriptState.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
#include "wtf/RefPtr.h"
#include <v8.h>
namespace WebCore {
class ExecutionContext;
class ScriptPromiseResolver : public RefCounted<ScriptPromiseResolver> {
WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver);
public:
static PassRefPtr<ScriptPromiseResolver> create(ExecutionContext*);
static PassRefPtr<ScriptPromiseResolver> create(v8::Isolate*);
~ScriptPromiseResolver();
ScriptPromise promise();
template<typename T>
void resolve(T* value, v8::Handle<v8::Object> creationContext) { resolve(toV8NoInline(value, creationContext, m_isolate)); }
template<typename T>
void reject(T* value, v8::Handle<v8::Object> creationContext) { reject(toV8NoInline(value, creationContext, m_isolate)); }
template<typename T>
void resolve(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
template<typename T>
void resolve(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
template<typename T>
void reject(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { reject(value.get(), creationContext); }
template<typename T>
void reject(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { reject(value.get(), creationContext); }
template<typename T>
inline void resolve(T* value, ExecutionContext*);
template<typename T>
inline void reject(T* value, ExecutionContext*);
template<typename T>
void resolve(PassRefPtr<T> value, ExecutionContext* context) { resolve(value.get(), context); }
template<typename T>
void resolve(RawPtr<T> value, ExecutionContext* context) { resolve(value.get(), context); }
template<typename T>
void reject(PassRefPtr<T> value, ExecutionContext* context) { reject(value.get(), context); }
template<typename T>
void reject(RawPtr<T> value, ExecutionContext* context) { reject(value.get(), context); }
template<typename T>
inline void resolve(T* value);
template<typename T>
inline void reject(T* value);
template<typename T, size_t inlineCapacity>
void resolve(const Vector<T, inlineCapacity>& iterator) { resolve(v8ArrayNoInline(iterator, m_isolate)); }
template<typename T, size_t inlineCapacity>
void reject(const Vector<T, inlineCapacity>& iterator) { reject(v8ArrayNoInline(iterator, m_isolate)); }
template<typename T>
void resolve(PassRefPtr<T> value) { resolve(value.get()); }
template<typename T>
void resolve(RawPtr<T> value) { resolve(value.get()); }
template<typename T>
void reject(PassRefPtr<T> value) { reject(value.get()); }
template<typename T>
void reject(RawPtr<T> value) { reject(value.get()); }
void resolve(ScriptValue);
void reject(ScriptValue);
private:
ScriptPromiseResolver(ExecutionContext*);
ScriptPromiseResolver(v8::Isolate*);
void resolve(v8::Handle<v8::Value>);
void reject(v8::Handle<v8::Value>);
v8::Isolate* m_isolate;
ScriptPromise m_promise;
ScriptValue m_resolver;
};
template<typename T>
void ScriptPromiseResolver::resolve(T* value, ExecutionContext* context)
{
ASSERT(m_isolate->InContext());
v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::current(m_isolate));
resolve(value, v8Context->Global());
}
template<typename T>
void ScriptPromiseResolver::reject(T* value, ExecutionContext* context)
{
ASSERT(m_isolate->InContext());
v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::current(m_isolate));
reject(value, v8Context->Global());
}
template<typename T>
void ScriptPromiseResolver::resolve(T* value)
{
ASSERT(m_isolate->InContext());
resolve(value, v8::Object::New(m_isolate));
}
template<typename T>
void ScriptPromiseResolver::reject(T* value)
{
ASSERT(m_isolate->InContext());
reject(value, v8::Object::New(m_isolate));
}
}
#endif