Revision: 8771
Author:   [email protected]
Date:     Mon Aug  1 07:15:02 2011
Log:      Fixed: regression in issue 1579 concerning readline() in d8.
BUG=v8:1579

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

Modified:
 /branches/bleeding_edge/src/d8.cc

=======================================
--- /branches/bleeding_edge/src/d8.cc   Tue Jul 26 01:15:49 2011
+++ /branches/bleeding_edge/src/d8.cc   Mon Aug  1 07:15:02 2011
@@ -226,17 +226,24 @@
   static const int kBufferSize = 256;
   char buffer[kBufferSize];
   Handle<String> accumulator = String::New("");
-  bool linebreak;
   int length;
-  do {  // Repeat if the line ends with an escape '\'.
-    // fgets got an error. Just give up.
+  while (true) {
+ // Continue reading if the line ends with an escape '\\' or the line has
+    // not been fully read into the buffer yet (does not end with '\n').
+    // If fgets gets an error, just give up.
     if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
     length = static_cast<int>(strlen(buffer));
-    linebreak = (length > 1 && buffer[length-2] == '\\');
-    if (linebreak) buffer[length-2] = '\n';
- accumulator = String::Concat(accumulator, String::New(buffer, length-1));
-  } while (linebreak);
-  return accumulator;
+    if (length == 0) {
+      return accumulator;
+    } else if (buffer[length-1] != '\n') {
+ accumulator = String::Concat(accumulator, String::New(buffer, length));
+    } else if (length > 1 && buffer[length-2] == '\\') {
+      buffer[length-2] = '\n';
+ accumulator = String::Concat(accumulator, String::New(buffer, length-1));
+    } else {
+      return String::Concat(accumulator, String::New(buffer, length-1));
+    }
+  }
 }


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

Reply via email to