]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/StringRecursionChecker.h
JavaScriptCore-1218.35.tar.gz
[apple/javascriptcore.git] / runtime / StringRecursionChecker.h
index 314f14eeb833b77266405580e25ab196ae6f4b2e..07dc25ababc5c856afcbddda4e1f3385cf5933c1 100644 (file)
@@ -21,6 +21,8 @@
 #define StringRecursionChecker_h
 
 #include "Interpreter.h"
+#include <wtf/StackStats.h>
+#include <wtf/WTFThreadData.h>
 
 namespace JSC {
 
@@ -31,27 +33,29 @@ public:
     StringRecursionChecker(ExecState*, JSObject* thisObject);
     ~StringRecursionChecker();
 
-    EncodedJSValue earlyReturnValue() const; // 0 if everything is OK, value to return for failure cases
+    JSValue earlyReturnValue() const; // 0 if everything is OK, value to return for failure cases
 
 private:
-    EncodedJSValue throwStackOverflowError();
-    EncodedJSValue emptyString();
-    EncodedJSValue performCheck();
+    JSValue throwStackOverflowError();
+    JSValue emptyString();
+    JSValue performCheck();
 
     ExecState* m_exec;
     JSObject* m_thisObject;
-    EncodedJSValue m_earlyReturnValue;
+    JSValue m_earlyReturnValue;
+
+    StackStats::CheckPoint stackCheckpoint;
 };
 
-inline EncodedJSValue StringRecursionChecker::performCheck()
+inline JSValue StringRecursionChecker::performCheck()
 {
-    int size = m_exec->globalData().stringRecursionCheckVisitedObjects.size();
-    if (size >= MaxSmallThreadReentryDepth && size >= m_exec->globalData().maxReentryDepth)
+    const StackBounds& nativeStack = wtfThreadData().stack();
+    if (!nativeStack.isSafeToRecurse())
         return throwStackOverflowError();
-    bool alreadyVisited = !m_exec->globalData().stringRecursionCheckVisitedObjects.add(m_thisObject).second;
+    bool alreadyVisited = !m_exec->vm().stringRecursionCheckVisitedObjects.add(m_thisObject).isNewEntry;
     if (alreadyVisited)
         return emptyString(); // Return empty string to avoid infinite recursion.
-    return 0; // Indicate success.
+    return JSValue(); // Indicate success.
 }
 
 inline StringRecursionChecker::StringRecursionChecker(ExecState* exec, JSObject* thisObject)
@@ -61,7 +65,7 @@ inline StringRecursionChecker::StringRecursionChecker(ExecState* exec, JSObject*
 {
 }
 
-inline EncodedJSValue StringRecursionChecker::earlyReturnValue() const
+inline JSValue StringRecursionChecker::earlyReturnValue() const
 {
     return m_earlyReturnValue;
 }
@@ -70,8 +74,8 @@ inline StringRecursionChecker::~StringRecursionChecker()
 {
     if (m_earlyReturnValue)
         return;
-    ASSERT(m_exec->globalData().stringRecursionCheckVisitedObjects.contains(m_thisObject));
-    m_exec->globalData().stringRecursionCheckVisitedObjects.remove(m_thisObject);
+    ASSERT(m_exec->vm().stringRecursionCheckVisitedObjects.contains(m_thisObject));
+    m_exec->vm().stringRecursionCheckVisitedObjects.remove(m_thisObject);
 }
 
 }