Reviewed by Maciej.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 May 2005 00:53:37 +0000 (00:53 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 May 2005 00:53:37 +0000 (00:53 +0000)
        - got rid of code that depended on RTTI

        * kjs/collector.cpp:
        (KJS::className): Added. Gets class name in a KJS way, rather than a C++ RTTI way.
        (KJS::Collector::rootObjectClasses): Use className instead of typeid names.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9180 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/collector.cpp

index cb59d2adfa117fe672ec3b75353f7c8dccc80e85..b11cf12e89f30a81cb123803fad28c1f3180795e 100644 (file)
@@ -1,3 +1,13 @@
+2005-05-18  Darin Adler  <darin@apple.com>
+
+        Reviewed by Maciej.
+
+        - got rid of code that depended on RTTI
+
+        * kjs/collector.cpp:
+        (KJS::className): Added. Gets class name in a KJS way, rather than a C++ RTTI way.
+        (KJS::Collector::rootObjectClasses): Use className instead of typeid names.
+
 2005-05-18  Darin Adler  <darin@apple.com>
 
         Reviewed by Maciej.
index 8fa955d6cafe6ea6db37249812fd309803699146..2ae83fa466450989497bb8a818f80ced54df47f3 100644 (file)
@@ -28,7 +28,6 @@
 
 #if APPLE_CHANGES
 #include <CoreFoundation/CoreFoundation.h>
-#include <cxxabi.h>
 #include <pthread.h>
 #include <mach/mach_port.h>
 #include <mach/task.h>
@@ -372,7 +371,7 @@ bool Collector::collect()
       if (cell->u.freeCell.zeroIfFree != 0) {
        if (!imp->_marked)
        {
-         //fprintf( stderr, "Collector::deleting ValueImp %p (%s)\n", (void*)imp, typeid(*imp).name());
+         //fprintf(stderr, "Collector::deleting ValueImp %p (%s)\n", imp, className(imp));
          // emulate destructing part of 'operator delete()'
          imp->~ValueImp();
          curBlock->usedCells--;
@@ -502,6 +501,36 @@ int Collector::numReferencedObjects()
 
 #if APPLE_CHANGES
 
+static const char *className(ValueImp *val)
+{
+  const char *name = "???";
+  switch (val->dispatchType()) {
+    case UnspecifiedType:
+      break;
+    case UndefinedType:
+      name = "undefined";
+      break;
+    case NullType:
+      name = "null";
+      break;
+    case BooleanType:
+      name = "boolean";
+      break;
+    case StringType:
+      name = "string";
+      break;
+    case NumberType:
+      name = "number";
+      break;
+    case ObjectType: {
+      const ClassInfo *info = static_cast<ObjectImp *>(val)->classInfo();
+      name = info ? info->className : "Object";
+      break;
+    }
+  }
+  return name;
+}
+
 const void *Collector::rootObjectClasses()
 {
   CFMutableSetRef classes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks);
@@ -511,14 +540,9 @@ const void *Collector::rootObjectClasses()
   for (int i = 0; i < size; i++) {
     ValueImp *val = table[i].key;
     if (val) {
-      const char *mangled_name = typeid(*val).name();
-      int status;
-      char *demangled_name = __cxxabiv1::__cxa_demangle (mangled_name, NULL, NULL, &status);
-      
-      CFStringRef className = CFStringCreateWithCString(NULL, demangled_name, kCFStringEncodingASCII);
-      free(demangled_name);
-      CFSetAddValue(classes, className);
-      CFRelease(className);
+      CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII);
+      CFSetAddValue(classes, name);
+      CFRelease(name);
     }
   }