From f2bcc90c8ce33d02a554d0d563a1b69af5a08599 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Tue, 12 Mar 2013 08:00:20 +0000 Subject: [PATCH] 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 --- src/d8-readline.cc | 14 ++++++++++---- src/d8.cc | 2 +- src/d8.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/d8-readline.cc b/src/d8-readline.cc index 8989263..cc7a3a6 100644 --- a/src/d8-readline.cc +++ b/src/d8-readline.cc @@ -49,7 +49,7 @@ class ReadLineEditor: public LineEditor { public: ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } virtual Handle Prompt(const char* prompt); - virtual bool Open(); + virtual bool Open(Isolate* isolate); virtual bool Close(); virtual void AddHistory(const char* str); @@ -62,6 +62,8 @@ class ReadLineEditor: public LineEditor { static char* CompletionGenerator(const char* text, int state); #endif // V8_SHARED static char kWordBreakCharacters[]; + + Isolate* isolate_; }; @@ -75,7 +77,9 @@ const char* ReadLineEditor::kHistoryFileName = ".d8_history"; const int ReadLineEditor::kMaxHistoryEntries = 1000; -bool ReadLineEditor::Open() { +bool ReadLineEditor::Open(Isolate* isolate) { + isolate_ = isolate; + rl_initialize(); #ifdef V8_SHARED @@ -144,12 +148,14 @@ char** ReadLineEditor::AttemptedCompletion(const char* text, char* ReadLineEditor::CompletionGenerator(const char* text, int state) { static unsigned current_index; static Persistent current_completions; + Isolate* isolate = read_line_editor.isolate_; + Locker lock(isolate); if (state == 0) { HandleScope scope; Local full_text = String::New(rl_line_buffer, rl_point); Handle completions = Shell::GetCompletions(String::New(text), full_text); - current_completions = Persistent::New(completions); + current_completions = Persistent::New(isolate, completions); current_index = 0; } if (current_index < current_completions->Length()) { @@ -160,7 +166,7 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { String::Utf8Value str(str_obj); return strdup(*str); } else { - current_completions.Dispose(); + current_completions.Dispose(isolate); current_completions.Clear(); return NULL; } diff --git a/src/d8.cc b/src/d8.cc index 2d30a1c..24c89e9 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -1497,7 +1497,7 @@ void Shell::RunShell(Isolate* isolate) { Handle name = String::New("(d8)"); LineEditor* console = LineEditor::Get(); printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); - console->Open(); + console->Open(isolate); while (true) { HandleScope inner_scope; Handle input = console->Prompt(Shell::kPrompt); diff --git a/src/d8.h b/src/d8.h index f3b3fa1..04c5454 100644 --- a/src/d8.h +++ b/src/d8.h @@ -123,7 +123,7 @@ class LineEditor { virtual ~LineEditor() { } virtual Handle Prompt(const char* prompt) = 0; - virtual bool Open() { return true; } + virtual bool Open(Isolate* isolate) { return true; } virtual bool Close() { return true; } virtual void AddHistory(const char* str) { } -- 2.7.4