#ifndef NewScriptState_h
#define NewScriptState_h
#include "bindings/v8/ScopedPersistent.h"
#include "bindings/v8/V8PerContextData.h"
#include "wtf/RefCounted.h"
#include <v8.h>
namespace WebCore {
class DOMWrapperWorld;
class ExecutionContext;
class NewScriptState : public RefCounted<NewScriptState> {
WTF_MAKE_NONCOPYABLE(NewScriptState);
public:
static PassRefPtr<NewScriptState> create(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
~NewScriptState();
static NewScriptState* current(v8::Isolate* isolate)
{
return from(isolate->GetCurrentContext());
}
static NewScriptState* from(v8::Handle<v8::Context> context)
{
ASSERT(!context.IsEmpty());
NewScriptState* scriptState = static_cast<NewScriptState*>(context->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex));
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState);
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == context);
return scriptState;
}
v8::Isolate* isolate() const { return m_isolate; }
DOMWrapperWorld& world() const { return *m_world; }
v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolate); }
void clearContext() { return m_context.clear(); }
ExecutionContext* executionContext() const;
V8PerContextData* perContextData() const { return m_perContextData.get(); }
void disposePerContextData() { m_perContextData = nullptr; }
private:
NewScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
v8::Isolate* m_isolate;
ScopedPersistent<v8::Context> m_context;
RefPtr<DOMWrapperWorld> m_world;
OwnPtr<V8PerContextData> m_perContextData;
};
}
#endif