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
This commit is contained in:
svenpanne@chromium.org 2013-03-12 08:00:20 +00:00
parent e02315ef77
commit f2bcc90c8c
3 changed files with 12 additions and 6 deletions

View 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;
}

View File

@ -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);

View File

@ -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) { }