JSMainThreadExecState.h [plain text]
#ifndef JSMainThreadExecState_h
#define JSMainThreadExecState_h
#include "JSDOMBinding.h"
#include <runtime/Completion.h>
#ifndef NDEBUG
#include <wtf/MainThread.h>
#endif
namespace WebCore {
class JSMainThreadExecState {
WTF_MAKE_NONCOPYABLE(JSMainThreadExecState);
public:
static JSC::ExecState* currentState()
{
ASSERT(WTF::isMainThread());
return s_mainThreadState;
};
static JSC::JSValue call(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args)
{
JSMainThreadExecState currentState(exec);
if (thisValue.isObject())
thisValue = thisValue.toThisObject(exec);
return JSC::call(exec, functionObject, callType, callData, thisValue, args);
};
static JSC::JSValue evaluate(JSC::ExecState* exec, JSC::ScopeChainNode* chain, const JSC::SourceCode& source, JSC::JSValue thisValue, JSC::JSValue* exception)
{
JSMainThreadExecState currentState(exec);
return JSC::evaluate(exec, chain, source, thisValue, exception);
};
protected:
explicit JSMainThreadExecState(JSC::ExecState* exec)
: m_previousState(s_mainThreadState)
{
ASSERT(WTF::isMainThread());
s_mainThreadState = exec;
};
~JSMainThreadExecState()
{
ASSERT(WTF::isMainThread());
s_mainThreadState = m_previousState;
}
private:
static JSC::ExecState* s_mainThreadState;
JSC::ExecState* m_previousState;
};
class JSMainThreadNullState : private JSMainThreadExecState {
public:
explicit JSMainThreadNullState() : JSMainThreadExecState(0) {};
};
}
#endif // JSMainThreadExecState_h