#ifndef JSPromise_h
#define JSPromise_h
#if ENABLE(PROMISES)
#include "JSDestructibleObject.h"
namespace JSC {
class JSPromiseReaction;
class JSPromiseConstructor;
class JSPromise : public JSDestructibleObject {
public:
typedef JSDestructibleObject Base;
static JSPromise* create(VM&, JSGlobalObject*, JSPromiseConstructor*);
static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
DECLARE_INFO;
enum class Status {
Unresolved,
HasResolution,
HasRejection
};
Status status() const
{
return m_status;
}
JSValue result() const
{
ASSERT(m_status != Status::Unresolved);
return m_result.get();
}
JSPromiseConstructor* constructor() const
{
return m_constructor.get();
}
void reject(VM&, JSValue);
void resolve(VM&, JSValue);
void appendResolveReaction(VM&, JSPromiseReaction*);
void appendRejectReaction(VM&, JSPromiseReaction*);
private:
JSPromise(VM&, Structure*);
void finishCreation(VM&, JSPromiseConstructor*);
static const unsigned StructureFlags = OverridesVisitChildren | JSObject::StructureFlags;
static void destroy(JSCell*);
static void visitChildren(JSCell*, SlotVisitor&);
Status m_status;
WriteBarrier<Unknown> m_result;
WriteBarrier<JSPromiseConstructor> m_constructor;
Vector<WriteBarrier<JSPromiseReaction>> m_resolveReactions;
Vector<WriteBarrier<JSPromiseReaction>> m_rejectReactions;
};
}
#endif // ENABLE(PROMISES)
#endif // JSPromise_h