| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> // NOLINT | 5 #include <stdio.h> // NOLINT |
| 6 #include <string.h> // NOLINT | 6 #include <string.h> // NOLINT |
| 7 #include <readline/readline.h> // NOLINT | 7 #include <readline/readline.h> // NOLINT |
| 8 #include <readline/history.h> // NOLINT | 8 #include <readline/history.h> // NOLINT |
| 9 | 9 |
| 10 // The readline includes leaves RETURN defined which breaks V8 compilation. | 10 // The readline includes leaves RETURN defined which breaks V8 compilation. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 bool ReadLineEditor::Close() { | 78 bool ReadLineEditor::Close() { |
| 79 return write_history(kHistoryFileName) == 0; | 79 return write_history(kHistoryFileName) == 0; |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 Handle<String> ReadLineEditor::Prompt(const char* prompt) { | 83 Handle<String> ReadLineEditor::Prompt(const char* prompt) { |
| 84 char* result = NULL; | 84 char* result = NULL; |
| 85 { // Release lock for blocking input. | 85 result = readline(prompt); |
| 86 Unlocker unlock(isolate_); | |
| 87 result = readline(prompt); | |
| 88 } | |
| 89 if (result == NULL) return Handle<String>(); | 86 if (result == NULL) return Handle<String>(); |
| 90 AddHistory(result); | 87 AddHistory(result); |
| 91 return String::NewFromUtf8(isolate_, result); | 88 return String::NewFromUtf8(isolate_, result); |
| 92 } | 89 } |
| 93 | 90 |
| 94 | 91 |
| 95 void ReadLineEditor::AddHistory(const char* str) { | 92 void ReadLineEditor::AddHistory(const char* str) { |
| 96 // Do not record empty input. | 93 // Do not record empty input. |
| 97 if (strlen(str) == 0) return; | 94 if (strlen(str) == 0) return; |
| 98 // Remove duplicate history entry. | 95 // Remove duplicate history entry. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 116 char** result = completion_matches(text, CompletionGenerator); | 113 char** result = completion_matches(text, CompletionGenerator); |
| 117 rl_attempted_completion_over = true; | 114 rl_attempted_completion_over = true; |
| 118 return result; | 115 return result; |
| 119 } | 116 } |
| 120 | 117 |
| 121 | 118 |
| 122 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { | 119 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { |
| 123 static unsigned current_index; | 120 static unsigned current_index; |
| 124 static Persistent<Array> current_completions; | 121 static Persistent<Array> current_completions; |
| 125 Isolate* isolate = read_line_editor.isolate_; | 122 Isolate* isolate = read_line_editor.isolate_; |
| 126 Locker lock(isolate); | |
| 127 HandleScope scope(isolate); | 123 HandleScope scope(isolate); |
| 128 Handle<Array> completions; | 124 Handle<Array> completions; |
| 129 if (state == 0) { | 125 if (state == 0) { |
| 130 Local<String> full_text = String::NewFromUtf8(isolate, | 126 Local<String> full_text = String::NewFromUtf8(isolate, |
| 131 rl_line_buffer, | 127 rl_line_buffer, |
| 132 String::kNormalString, | 128 String::kNormalString, |
| 133 rl_point); | 129 rl_point); |
| 134 completions = Shell::GetCompletions(isolate, | 130 completions = Shell::GetCompletions(isolate, |
| 135 String::NewFromUtf8(isolate, text), | 131 String::NewFromUtf8(isolate, text), |
| 136 full_text); | 132 full_text); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 return strdup(*str); | 143 return strdup(*str); |
| 148 } else { | 144 } else { |
| 149 current_completions.Reset(); | 145 current_completions.Reset(); |
| 150 return NULL; | 146 return NULL; |
| 151 } | 147 } |
| 152 } | 148 } |
| 153 #endif // V8_SHARED | 149 #endif // V8_SHARED |
| 154 | 150 |
| 155 | 151 |
| 156 } // namespace v8 | 152 } // namespace v8 |
| OLD | NEW |