#ifndef APIShims_h
#define APIShims_h
#include "CallFrame.h"
#include "GCActivityCallback.h"
#include "JSLock.h"
#include <wtf/WTFThreadData.h>
namespace JSC {
class APIEntryShimWithoutLock {
protected:
APIEntryShimWithoutLock(JSGlobalData* globalData, bool registerThread)
: m_globalData(globalData)
, m_entryIdentifierTable(wtfThreadData().setCurrentIdentifierTable(globalData->identifierTable))
{
UNUSED_PARAM(registerThread);
#if ENABLE(JSC_MULTIPLE_THREADS)
if (registerThread)
globalData->heap.machineThreads().addCurrentThread();
#endif
m_globalData->heap.activityCallback()->synchronize();
m_globalData->timeoutChecker.start();
}
~APIEntryShimWithoutLock()
{
m_globalData->timeoutChecker.stop();
wtfThreadData().setCurrentIdentifierTable(m_entryIdentifierTable);
}
private:
JSGlobalData* m_globalData;
IdentifierTable* m_entryIdentifierTable;
};
class APIEntryShim : public APIEntryShimWithoutLock {
public:
APIEntryShim(ExecState* exec, bool registerThread = true)
: APIEntryShimWithoutLock(&exec->globalData(), registerThread)
, m_lock(exec)
{
}
APIEntryShim(JSGlobalData* globalData, bool registerThread = true)
: APIEntryShimWithoutLock(globalData, registerThread)
, m_lock(globalData->isSharedInstance() ? LockForReal : SilenceAssertionsOnly)
{
}
private:
JSLock m_lock;
};
class APICallbackShim {
public:
APICallbackShim(ExecState* exec)
: m_dropAllLocks(exec)
, m_globalData(&exec->globalData())
{
wtfThreadData().resetCurrentIdentifierTable();
}
~APICallbackShim()
{
m_globalData->heap.activityCallback()->synchronize();
wtfThreadData().setCurrentIdentifierTable(m_globalData->identifierTable);
}
private:
JSLock::DropAllLocks m_dropAllLocks;
JSGlobalData* m_globalData;
};
}
#endif