Modifies readline() to behave in the same way as it does in TraceMonkey.
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 7 Sep 2009 12:37:56 +0000 (12:37 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 7 Sep 2009 12:37:56 +0000 (12:37 +0000)
Author: abdulla <abdulla.kamar@gmail.com>
Review URL: http://codereview.chromium.org/173262

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2838 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/d8.cc

index ce48dc9..e4658b1 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -179,15 +179,15 @@ Handle<Value> Shell::Read(const Arguments& args) {
 
 
 Handle<Value> Shell::ReadLine(const Arguments& args) {
-  char line_buf[256];
-  if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) {
-    return ThrowException(String::New("Error reading line"));
+  i::SmartPointer<char> line(i::ReadLine(""));
+  if (*line == NULL) {
+    return Null();
   }
-  int len = strlen(line_buf);
-  if (line_buf[len - 1] == '\n') {
+  size_t len = strlen(*line);
+  if (len > 0 && line[len - 1] == '\n') {
     --len;
   }
-  return String::New(line_buf, len);
+  return String::New(*line, len);
 }