Revision: 8763
Author:   [email protected]
Date:     Fri Jul 29 02:49:40 2011
Log:      String to ascii char array converter for debug mode.

Review URL: http://codereview.chromium.org/7523052
http://code.google.com/p/v8/source/detail?r=8763

Modified:
 /branches/bleeding_edge/src/objects-printer.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/src/objects-printer.cc      Fri Jul 22 02:04:16 2011
+++ /branches/bleeding_edge/src/objects-printer.cc      Fri Jul 29 02:49:40 2011
@@ -558,6 +558,21 @@

   if (!StringShape(this).IsSymbol()) PrintF(out, "\"");
 }
+
+
+// This method is only meant to be called from gdb for debugging purposes.
+// Since the string can also be in two-byte encoding, non-ascii characters
+// will be ignored in the output.
+char* String::ToAsciiArray() {
+  // Static so that subsequent calls frees previously allocated space.
+  // This also means that previous results will be overwritten.
+  static char* buffer = NULL;
+  if (buffer != NULL) free(buffer);
+  buffer = new char[length()+1];
+  WriteToFlat(this, buffer, 0, length());
+  buffer[length()] = 0;
+  return buffer;
+}


 void JSProxy::JSProxyPrint(FILE* out) {
=======================================
--- /branches/bleeding_edge/src/objects.h       Thu Jul 28 10:21:22 2011
+++ /branches/bleeding_edge/src/objects.h       Fri Jul 29 02:49:40 2011
@@ -5927,6 +5927,8 @@
     StringPrint(stdout);
   }
   void StringPrint(FILE* out);
+
+  char* ToAsciiArray();
 #endif
 #ifdef DEBUG
   void StringVerify();

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to