Reviewers: Sven,
Message:
PTAL.
Description:
Remove limit for d8 shell input length.
BUG=
TEST=
Please review this at http://codereview.chromium.org/9232009/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/d8-readline.cc
M src/d8.h
M src/d8.cc
Index: src/d8-readline.cc
diff --git a/src/d8-readline.cc b/src/d8-readline.cc
index
71be933109be193c6a80ef5f5a613fcd325dd830..679c5366f21854028ac35034fd9fdfd3f7441fb7
100644
--- a/src/d8-readline.cc
+++ b/src/d8-readline.cc
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -49,10 +49,14 @@ namespace v8 {
class ReadLineEditor: public LineEditor {
public:
ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
- virtual i::SmartArrayPointer<char> Prompt(const char* prompt);
+ virtual Handle<String> Prompt(const char* prompt);
virtual bool Open();
virtual bool Close();
virtual void AddHistory(const char* str);
+
+ static const char* kHistoryFileName;
+ static const int kMaxHistoryEntries;
+
private:
static char** AttemptedCompletion(const char* text, int start, int end);
static char* CompletionGenerator(const char* text, int state);
@@ -66,25 +70,34 @@ char ReadLineEditor::kWordBreakCharacters[] =
{' ', '\t', '\n', '"',
'\0'};
+const char* ReadLineEditor::kHistoryFileName = ".d8_history";
+const int ReadLineEditor::kMaxHistoryEntries = 1000;
+
+
bool ReadLineEditor::Open() {
rl_initialize();
rl_attempted_completion_function = AttemptedCompletion;
rl_completer_word_break_characters = kWordBreakCharacters;
rl_bind_key('\t', rl_complete);
using_history();
- stifle_history(Shell::kMaxHistoryEntries);
- return read_history(Shell::kHistoryFileName) == 0;
+ stifle_history(kMaxHistoryEntries);
+ return read_history(kHistoryFileName) == 0;
}
bool ReadLineEditor::Close() {
- return write_history(Shell::kHistoryFileName) == 0;
+ return write_history(kHistoryFileName) == 0;
}
-i::SmartArrayPointer<char> ReadLineEditor::Prompt(const char* prompt) {
+Handle<String> ReadLineEditor::Prompt(const char* prompt) {
char* result = readline(prompt);
- return i::SmartArrayPointer<char>(result);
+ if (result != NULL) {
+ AddHistory(result);
+ } else {
+ return Handle<String>();
+ }
+ return String::New(result);
}
@@ -118,10 +131,10 @@ char* ReadLineEditor::CompletionGenerator(const char*
text, int state) {
static unsigned current_index;
static Persistent<Array> current_completions;
if (state == 0) {
- i::SmartArrayPointer<char> full_text(i::StrNDup(rl_line_buffer,
rl_point));
HandleScope scope;
+ Local<String> full_text = String::New(rl_line_buffer, rl_point);
Handle<Array> completions =
- Shell::GetCompletions(String::New(text), String::New(*full_text));
+ Shell::GetCompletions(String::New(text), full_text);
current_completions = Persistent<Array>::New(completions);
current_index = 0;
}
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index
97828a4ac4c6027d4fef17ff42959a7981772fa9..b612c482a96573659a00b382050d54a4c34dd536
100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -66,11 +66,7 @@
namespace v8 {
-
-#ifndef V8_SHARED
LineEditor *LineEditor::first_ = NULL;
-const char* Shell::kHistoryFileName = ".d8_history";
-const int Shell::kMaxHistoryEntries = 1000;
LineEditor::LineEditor(Type type, const char* name)
@@ -96,31 +92,29 @@ LineEditor* LineEditor::Get() {
class DumbLineEditor: public LineEditor {
public:
DumbLineEditor() : LineEditor(LineEditor::DUMB, "dumb") { }
- virtual i::SmartArrayPointer<char> Prompt(const char* prompt);
+ virtual Handle<String> Prompt(const char* prompt);
};
static DumbLineEditor dumb_line_editor;
-i::SmartArrayPointer<char> DumbLineEditor::Prompt(const char* prompt) {
- static const int kBufferSize = 256;
- char buffer[kBufferSize];
+Handle<String> DumbLineEditor::Prompt(const char* prompt) {
printf("%s", prompt);
- char* str = fgets(buffer, kBufferSize, stdin);
- return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str);
+ return Shell::ReadFromStdin();
}
+#ifndef V8_SHARED
CounterMap* Shell::counter_map_;
i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
CounterCollection Shell::local_counters_;
CounterCollection* Shell::counters_ = &local_counters_;
i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
Persistent<Context> Shell::utility_context_;
-LineEditor* Shell::console = NULL;
#endif // V8_SHARED
+LineEditor* Shell::console = NULL;
Persistent<Context> Shell::evaluation_context_;
ShellOptions Shell::options;
const char* Shell::kPrompt = "d8> ";
@@ -238,7 +232,7 @@ Handle<Value> Shell::Read(const Arguments& args) {
}
-Handle<Value> Shell::ReadLine(const Arguments& args) {
+Handle<String> Shell::ReadFromStdin() {
static const int kBufferSize = 256;
char buffer[kBufferSize];
Handle<String> accumulator = String::New("");
@@ -247,7 +241,7 @@ Handle<Value> Shell::ReadLine(const Arguments& args) {
// 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();
+ if (fgets(buffer, kBufferSize, stdin) == NULL) return Handle<String>();
length = static_cast<int>(strlen(buffer));
if (length == 0) {
return accumulator;
@@ -1047,28 +1041,15 @@ void Shell::RunShell() {
Context::Scope context_scope(evaluation_context_);
HandleScope outer_scope;
Handle<String> name = String::New("(d8)");
-#ifndef V8_SHARED
console = LineEditor::Get();
printf("V8 version %s [console: %s]\n", V8::GetVersion(),
console->name());
console->Open();
while (true) {
- i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt);
- if (input.is_empty()) break;
- console->AddHistory(*input);
HandleScope inner_scope;
- ExecuteString(String::New(*input), name, true, true);
+ Handle<String> input = console->Prompt(Shell::kPrompt);
+ if (input.IsEmpty()) break;
+ ExecuteString(input, name, true, true);
}
-#else
- printf("V8 version %s [D8 light using shared library]\n",
V8::GetVersion());
- static const int kBufferSize = 256;
- while (true) {
- char buffer[kBufferSize];
- printf("%s", Shell::kPrompt);
- if (fgets(buffer, kBufferSize, stdin) == NULL) break;
- HandleScope inner_scope;
- ExecuteString(String::New(buffer), name, true, true);
- }
-#endif // V8_SHARED
printf("\n");
}
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index
6c7733ccfaf1a4bede8308f969c283ed70486c14..e9b417be7d0a90e6e8b0447f1038ce27dcea2e97
100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -116,14 +116,13 @@ class CounterMap {
#endif // V8_SHARED
-#ifndef V8_SHARED
class LineEditor {
public:
enum Type { DUMB = 0, READLINE = 1 };
LineEditor(Type type, const char* name);
virtual ~LineEditor() { }
- virtual i::SmartArrayPointer<char> Prompt(const char* prompt) = 0;
+ virtual Handle<String> Prompt(const char* prompt) = 0;
virtual bool Open() { return true; }
virtual bool Close() { return true; }
virtual void AddHistory(const char* str) { }
@@ -136,7 +135,6 @@ class LineEditor {
LineEditor* next_;
static LineEditor* first_;
};
-#endif // V8_SHARED
class SourceGroup {
@@ -287,7 +285,10 @@ class Shell : public i::AllStatic {
static Handle<Value> EnableProfiler(const Arguments& args);
static Handle<Value> DisableProfiler(const Arguments& args);
static Handle<Value> Read(const Arguments& args);
- static Handle<Value> ReadLine(const Arguments& args);
+ static Handle<String> ReadFromStdin();
+ static Handle<Value> ReadLine(const Arguments& args) {
+ return ReadFromStdin();
+ }
static Handle<Value> Load(const Arguments& args);
static Handle<Value> ArrayBuffer(const Arguments& args);
static Handle<Value> Int8Array(const Arguments& args);
@@ -335,11 +336,8 @@ class Shell : public i::AllStatic {
static Handle<Value> RemoveDirectory(const Arguments& args);
static void AddOSMethods(Handle<ObjectTemplate> os_template);
-#ifndef V8_SHARED
- static const char* kHistoryFileName;
- static const int kMaxHistoryEntries;
+
static LineEditor* console;
-#endif // V8_SHARED
static const char* kPrompt;
static ShellOptions options;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev