]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/Identifier.h
JavaScriptCore-584.tar.gz
[apple/javascriptcore.git] / runtime / Identifier.h
index 631cf42f7edfb4f3ffeca857fe88cbe94e14e615..35822258ef37a2d4fd9c565d4450d73b16fd85f3 100644 (file)
@@ -22,6 +22,7 @@
 #define Identifier_h
 
 #include "JSGlobalData.h"
+#include "ThreadSpecific.h"
 #include "UString.h"
 
 namespace JSC {
@@ -54,6 +55,8 @@ namespace JSC {
         const char* ascii() const { return _ustring.ascii(); }
         
         static Identifier from(ExecState* exec, unsigned y) { return Identifier(exec, UString::from(y)); }
+        static Identifier from(ExecState* exec, int y) { return Identifier(exec, UString::from(y)); }
+        static Identifier from(ExecState* exec, double y) { return Identifier(exec, UString::from(y)); }
         
         bool isNull() const { return _ustring.isNull(); }
         bool isEmpty() const { return _ustring.isEmpty(); }
@@ -90,7 +93,7 @@ namespace JSC {
 
         static PassRefPtr<UString::Rep> add(ExecState* exec, UString::Rep* r)
         {
-            if (r->identifierTable()) {
+            if (r->isIdentifier()) {
 #ifndef NDEBUG
                 checkSameIdentifierTable(exec, r);
 #endif
@@ -100,7 +103,7 @@ namespace JSC {
         }
         static PassRefPtr<UString::Rep> add(JSGlobalData* globalData, UString::Rep* r)
         {
-            if (r->identifierTable()) {
+            if (r->isIdentifier()) {
 #ifndef NDEBUG
                 checkSameIdentifierTable(globalData, r);
 #endif
@@ -139,6 +142,97 @@ namespace JSC {
     IdentifierTable* createIdentifierTable();
     void deleteIdentifierTable(IdentifierTable*);
 
+    struct ThreadIdentifierTableData {
+        ThreadIdentifierTableData()
+            : defaultIdentifierTable(0)
+            , currentIdentifierTable(0)
+        {
+        }
+
+        IdentifierTable* defaultIdentifierTable;
+        IdentifierTable* currentIdentifierTable;
+    };
+
+    extern WTF::ThreadSpecific<ThreadIdentifierTableData>* g_identifierTableSpecific;
+    extern ThreadIdentifierTableData* g_identifierTableMain;
+    void createIdentifierTableSpecific();
+
+    inline IdentifierTable* defaultIdentifierTable()
+    {
+        if (isMainThread() || pthread_main_np()) {
+            if (!g_identifierTableMain)
+                createIdentifierTableSpecific();
+            return g_identifierTableMain->defaultIdentifierTable;
+        }
+        if (!g_identifierTableSpecific)
+            createIdentifierTableSpecific();
+        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
+
+        return data.defaultIdentifierTable;
+    }
+
+    inline void setDefaultIdentifierTable(IdentifierTable* identifierTable)
+    {
+        if (isMainThread() || pthread_main_np()) {
+            if (!g_identifierTableMain)
+                createIdentifierTableSpecific();
+            g_identifierTableMain->defaultIdentifierTable = identifierTable;
+            return;
+        }
+        if (!g_identifierTableSpecific)
+            createIdentifierTableSpecific();
+        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
+
+        data.defaultIdentifierTable = identifierTable;
+    }
+
+    inline IdentifierTable* currentIdentifierTable()
+    {
+        if (isMainThread() || pthread_main_np()) {
+            if (!g_identifierTableMain)
+                createIdentifierTableSpecific();
+            return g_identifierTableMain->currentIdentifierTable;
+        }
+        if (!g_identifierTableSpecific)
+            createIdentifierTableSpecific();
+        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
+
+        return data.currentIdentifierTable;
+    }
+
+    inline IdentifierTable* setCurrentIdentifierTable(IdentifierTable* identifierTable)
+    {
+        if (isMainThread() || pthread_main_np()) {
+            if (!g_identifierTableMain)
+                createIdentifierTableSpecific();
+            IdentifierTable* oldIdentifierTable = g_identifierTableMain->currentIdentifierTable;
+            g_identifierTableMain->currentIdentifierTable = identifierTable;
+            return oldIdentifierTable;
+        }
+        if (!g_identifierTableSpecific)
+            createIdentifierTableSpecific();
+        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
+
+        IdentifierTable* oldIdentifierTable = data.currentIdentifierTable;
+        data.currentIdentifierTable = identifierTable;
+        return oldIdentifierTable;
+    }
+
+    inline void resetCurrentIdentifierTable()
+    {
+        if (isMainThread() || pthread_main_np()) {
+            if (!g_identifierTableMain)
+                createIdentifierTableSpecific();
+            g_identifierTableMain->currentIdentifierTable = g_identifierTableMain->defaultIdentifierTable;
+            return;
+        }
+        if (!g_identifierTableSpecific)
+            createIdentifierTableSpecific();
+        ThreadIdentifierTableData& data = **g_identifierTableSpecific;
+
+        data.currentIdentifierTable = data.defaultIdentifierTable;
+    }
+
 } // namespace JSC
 
 #endif // Identifier_h