| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return write_history(kHistoryFileName) == 0; | 102 return write_history(kHistoryFileName) == 0; |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 Handle<String> ReadLineEditor::Prompt(const char* prompt) { | 106 Handle<String> ReadLineEditor::Prompt(const char* prompt) { |
| 107 char* result = NULL; | 107 char* result = NULL; |
| 108 { // Release lock for blocking input. | 108 { // Release lock for blocking input. |
| 109 Unlocker unlock(Isolate::GetCurrent()); | 109 Unlocker unlock(Isolate::GetCurrent()); |
| 110 result = readline(prompt); | 110 result = readline(prompt); |
| 111 } | 111 } |
| 112 if (result != NULL) { | 112 if (result == NULL) return Handle<String>(); |
| 113 AddHistory(result); | 113 AddHistory(result); |
| 114 } else { | 114 return String::NewFromUtf8(isolate_, result); |
| 115 return Handle<String>(); | |
| 116 } | |
| 117 return String::New(result); | |
| 118 } | 115 } |
| 119 | 116 |
| 120 | 117 |
| 121 void ReadLineEditor::AddHistory(const char* str) { | 118 void ReadLineEditor::AddHistory(const char* str) { |
| 122 // Do not record empty input. | 119 // Do not record empty input. |
| 123 if (strlen(str) == 0) return; | 120 if (strlen(str) == 0) return; |
| 124 // Remove duplicate history entry. | 121 // Remove duplicate history entry. |
| 125 history_set_pos(history_length-1); | 122 history_set_pos(history_length-1); |
| 126 if (current_history()) { | 123 if (current_history()) { |
| 127 do { | 124 do { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 146 | 143 |
| 147 | 144 |
| 148 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { | 145 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { |
| 149 static unsigned current_index; | 146 static unsigned current_index; |
| 150 static Persistent<Array> current_completions; | 147 static Persistent<Array> current_completions; |
| 151 Isolate* isolate = read_line_editor.isolate_; | 148 Isolate* isolate = read_line_editor.isolate_; |
| 152 Locker lock(isolate); | 149 Locker lock(isolate); |
| 153 HandleScope scope(isolate); | 150 HandleScope scope(isolate); |
| 154 Handle<Array> completions; | 151 Handle<Array> completions; |
| 155 if (state == 0) { | 152 if (state == 0) { |
| 156 Local<String> full_text = String::New(rl_line_buffer, rl_point); | 153 Local<String> full_text = String::NewFromUtf8(isolate, |
| 157 completions = Shell::GetCompletions(isolate, String::New(text), full_text); | 154 rl_line_buffer, |
| 155 String::kNormalString, |
| 156 rl_point); |
| 157 completions = Shell::GetCompletions(isolate, |
| 158 String::NewFromUtf8(isolate, text), |
| 159 full_text); |
| 158 current_completions.Reset(isolate, completions); | 160 current_completions.Reset(isolate, completions); |
| 159 current_index = 0; | 161 current_index = 0; |
| 160 } else { | 162 } else { |
| 161 completions = Local<Array>::New(isolate, current_completions); | 163 completions = Local<Array>::New(isolate, current_completions); |
| 162 } | 164 } |
| 163 if (current_index < completions->Length()) { | 165 if (current_index < completions->Length()) { |
| 164 Handle<Integer> index = Integer::New(current_index); | 166 Handle<Integer> index = Integer::New(current_index); |
| 165 Handle<Value> str_obj = completions->Get(index); | 167 Handle<Value> str_obj = completions->Get(index); |
| 166 current_index++; | 168 current_index++; |
| 167 String::Utf8Value str(str_obj); | 169 String::Utf8Value str(str_obj); |
| 168 return strdup(*str); | 170 return strdup(*str); |
| 169 } else { | 171 } else { |
| 170 current_completions.Reset(); | 172 current_completions.Reset(); |
| 171 return NULL; | 173 return NULL; |
| 172 } | 174 } |
| 173 } | 175 } |
| 174 #endif // V8_SHARED | 176 #endif // V8_SHARED |
| 175 | 177 |
| 176 | 178 |
| 177 } // namespace v8 | 179 } // namespace v8 |
| OLD | NEW |