Unbreak readline support.
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 12 Mar 2013 08:00:20 +0000 (08:00 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 12 Mar 2013 08:00:20 +0000 (08:00 +0000)
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
src/d8.cc
src/d8.h

index 8989263..cc7a3a6 100644 (file)
@@ -49,7 +49,7 @@ class ReadLineEditor: public LineEditor {
  public:
   ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
   virtual Handle<String> 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<Array> current_completions;
+  Isolate* isolate = read_line_editor.isolate_;
+  Locker lock(isolate);
   if (state == 0) {
     HandleScope scope;
     Local<String> full_text = String::New(rl_line_buffer, rl_point);
     Handle<Array> completions =
       Shell::GetCompletions(String::New(text), full_text);
-    current_completions = Persistent<Array>::New(completions);
+    current_completions = Persistent<Array>::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;
   }
index 2d30a1c..24c89e9 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1497,7 +1497,7 @@ void Shell::RunShell(Isolate* isolate) {
   Handle<String> 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<String> input = console->Prompt(Shell::kPrompt);
index f3b3fa1..04c5454 100644 (file)
--- a/src/d8.h
+++ b/src/d8.h
@@ -123,7 +123,7 @@ class LineEditor {
   virtual ~LineEditor() { }
 
   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 void AddHistory(const char* str) { }