StringRecursionChecker.h [plain text]
#ifndef StringRecursionChecker_h
#define StringRecursionChecker_h
#include "Interpreter.h"
namespace JSC {
class StringRecursionChecker {
WTF_MAKE_NONCOPYABLE(StringRecursionChecker);
public:
StringRecursionChecker(ExecState*, JSObject* thisObject);
~StringRecursionChecker();
EncodedJSValue earlyReturnValue() const;
private:
EncodedJSValue throwStackOverflowError();
EncodedJSValue emptyString();
EncodedJSValue performCheck();
ExecState* m_exec;
JSObject* m_thisObject;
EncodedJSValue m_earlyReturnValue;
};
inline EncodedJSValue StringRecursionChecker::performCheck()
{
int size = m_exec->globalData().stringRecursionCheckVisitedObjects.size();
if (size >= MaxSmallThreadReentryDepth && size >= m_exec->globalData().maxReentryDepth)
return throwStackOverflowError();
bool alreadyVisited = !m_exec->globalData().stringRecursionCheckVisitedObjects.add(m_thisObject).second;
if (alreadyVisited)
return emptyString(); return 0; }
inline StringRecursionChecker::StringRecursionChecker(ExecState* exec, JSObject* thisObject)
: m_exec(exec)
, m_thisObject(thisObject)
, m_earlyReturnValue(performCheck())
{
}
inline EncodedJSValue StringRecursionChecker::earlyReturnValue() const
{
return m_earlyReturnValue;
}
inline StringRecursionChecker::~StringRecursionChecker()
{
if (m_earlyReturnValue)
return;
ASSERT(m_exec->globalData().stringRecursionCheckVisitedObjects.contains(m_thisObject));
m_exec->globalData().stringRecursionCheckVisitedObjects.remove(m_thisObject);
}
}
#endif