Unbreak readline support.

Things are still far from being nice, the editor registration/handling in d8 is
still embarrassing. Nevertheless things work with readline support again. Fixed
a missing Locker on the way.

TBR=adamk@chromium.org

Review URL: https://codereview.chromium.org/12494010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13909 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e02315ef
...@@ -49,7 +49,7 @@ class ReadLineEditor: public LineEditor { ...@@ -49,7 +49,7 @@ class ReadLineEditor: public LineEditor {
public: public:
ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
virtual Handle<String> Prompt(const char* prompt); virtual Handle<String> Prompt(const char* prompt);
virtual bool Open(); virtual bool Open(Isolate* isolate);
virtual bool Close(); virtual bool Close();
virtual void AddHistory(const char* str); virtual void AddHistory(const char* str);
...@@ -62,6 +62,8 @@ class ReadLineEditor: public LineEditor { ...@@ -62,6 +62,8 @@ class ReadLineEditor: public LineEditor {
static char* CompletionGenerator(const char* text, int state); static char* CompletionGenerator(const char* text, int state);
#endif // V8_SHARED #endif // V8_SHARED
static char kWordBreakCharacters[]; static char kWordBreakCharacters[];
Isolate* isolate_;
}; };
...@@ -75,7 +77,9 @@ const char* ReadLineEditor::kHistoryFileName = ".d8_history"; ...@@ -75,7 +77,9 @@ const char* ReadLineEditor::kHistoryFileName = ".d8_history";
const int ReadLineEditor::kMaxHistoryEntries = 1000; const int ReadLineEditor::kMaxHistoryEntries = 1000;
bool ReadLineEditor::Open() { bool ReadLineEditor::Open(Isolate* isolate) {
isolate_ = isolate;
rl_initialize(); rl_initialize();
#ifdef V8_SHARED #ifdef V8_SHARED
...@@ -144,12 +148,14 @@ char** ReadLineEditor::AttemptedCompletion(const char* text, ...@@ -144,12 +148,14 @@ char** ReadLineEditor::AttemptedCompletion(const char* text,
char* ReadLineEditor::CompletionGenerator(const char* text, int state) { char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
static unsigned current_index; static unsigned current_index;
static Persistent<Array> current_completions; static Persistent<Array> current_completions;
Isolate* isolate = read_line_editor.isolate_;
Locker lock(isolate);
if (state == 0) { if (state == 0) {
HandleScope scope; HandleScope scope;
Local<String> full_text = String::New(rl_line_buffer, rl_point); Local<String> full_text = String::New(rl_line_buffer, rl_point);
Handle<Array> completions = Handle<Array> completions =
Shell::GetCompletions(String::New(text), full_text); Shell::GetCompletions(String::New(text), full_text);
current_completions = Persistent<Array>::New(completions); current_completions = Persistent<Array>::New(isolate, completions);
current_index = 0; current_index = 0;
} }
if (current_index < current_completions->Length()) { if (current_index < current_completions->Length()) {
...@@ -160,7 +166,7 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { ...@@ -160,7 +166,7 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
String::Utf8Value str(str_obj); String::Utf8Value str(str_obj);
return strdup(*str); return strdup(*str);
} else { } else {
current_completions.Dispose(); current_completions.Dispose(isolate);
current_completions.Clear(); current_completions.Clear();
return NULL; return NULL;
} }
......
...@@ -1497,7 +1497,7 @@ void Shell::RunShell(Isolate* isolate) { ...@@ -1497,7 +1497,7 @@ void Shell::RunShell(Isolate* isolate) {
Handle<String> name = String::New("(d8)"); Handle<String> name = String::New("(d8)");
LineEditor* console = LineEditor::Get(); LineEditor* console = LineEditor::Get();
printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
console->Open(); console->Open(isolate);
while (true) { while (true) {
HandleScope inner_scope; HandleScope inner_scope;
Handle<String> input = console->Prompt(Shell::kPrompt); Handle<String> input = console->Prompt(Shell::kPrompt);
......
...@@ -123,7 +123,7 @@ class LineEditor { ...@@ -123,7 +123,7 @@ class LineEditor {
virtual ~LineEditor() { } virtual ~LineEditor() { }
virtual Handle<String> Prompt(const char* prompt) = 0; virtual Handle<String> Prompt(const char* prompt) = 0;
virtual bool Open() { return true; } virtual bool Open(Isolate* isolate) { return true; }
virtual bool Close() { return true; } virtual bool Close() { return true; }
virtual void AddHistory(const char* str) { } virtual void AddHistory(const char* str) { }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment