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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Local<String> ReadLineEditor::Prompt(const char* prompt) { | 83 Local<String> ReadLineEditor::Prompt(const char* prompt) { |
84 char* result = NULL; | 84 char* result = NULL; |
85 result = readline(prompt); | 85 result = readline(prompt); |
86 if (result == NULL) return Local<String>(); | 86 if (result == NULL) return Local<String>(); |
87 AddHistory(result); | 87 AddHistory(result); |
88 return String::NewFromUtf8(isolate_, result); | 88 return String::NewFromUtf8(isolate_, result, NewStringType::kNormal) |
| 89 .ToLocalChecked(); |
89 } | 90 } |
90 | 91 |
91 | 92 |
92 void ReadLineEditor::AddHistory(const char* str) { | 93 void ReadLineEditor::AddHistory(const char* str) { |
93 // Do not record empty input. | 94 // Do not record empty input. |
94 if (strlen(str) == 0) return; | 95 if (strlen(str) == 0) return; |
95 // Remove duplicate history entry. | 96 // Remove duplicate history entry. |
96 history_set_pos(history_length-1); | 97 history_set_pos(history_length-1); |
97 if (current_history()) { | 98 if (current_history()) { |
98 do { | 99 do { |
(...skipping 17 matching lines...) Expand all Loading... |
116 } | 117 } |
117 | 118 |
118 | 119 |
119 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { | 120 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { |
120 static unsigned current_index; | 121 static unsigned current_index; |
121 static Global<Array> current_completions; | 122 static Global<Array> current_completions; |
122 Isolate* isolate = read_line_editor.isolate_; | 123 Isolate* isolate = read_line_editor.isolate_; |
123 HandleScope scope(isolate); | 124 HandleScope scope(isolate); |
124 Local<Array> completions; | 125 Local<Array> completions; |
125 if (state == 0) { | 126 if (state == 0) { |
126 Local<String> full_text = String::NewFromUtf8(isolate, | 127 Local<String> full_text = |
127 rl_line_buffer, | 128 String::NewFromUtf8(isolate, rl_line_buffer, NewStringType::kNormal, |
128 String::kNormalString, | 129 rl_point) |
129 rl_point); | 130 .ToLocalChecked(); |
130 completions = Shell::GetCompletions(isolate, | 131 completions = Shell::GetCompletions( |
131 String::NewFromUtf8(isolate, text), | 132 isolate, String::NewFromUtf8(isolate, text, NewStringType::kNormal) |
132 full_text); | 133 .ToLocalChecked(), |
| 134 full_text); |
133 current_completions.Reset(isolate, completions); | 135 current_completions.Reset(isolate, completions); |
134 current_index = 0; | 136 current_index = 0; |
135 } else { | 137 } else { |
136 completions = Local<Array>::New(isolate, current_completions); | 138 completions = Local<Array>::New(isolate, current_completions); |
137 } | 139 } |
138 if (current_index < completions->Length()) { | 140 if (current_index < completions->Length()) { |
| 141 Local<Context> context(isolate->GetCurrentContext()); |
139 Local<Integer> index = Integer::New(isolate, current_index); | 142 Local<Integer> index = Integer::New(isolate, current_index); |
140 Local<Value> str_obj = completions->Get(index); | 143 Local<Value> str_obj = completions->Get(context, index).ToLocalChecked(); |
141 current_index++; | 144 current_index++; |
142 String::Utf8Value str(str_obj); | 145 String::Utf8Value str(str_obj); |
143 return strdup(*str); | 146 return strdup(*str); |
144 } else { | 147 } else { |
145 current_completions.Reset(); | 148 current_completions.Reset(); |
146 return NULL; | 149 return NULL; |
147 } | 150 } |
148 } | 151 } |
149 #endif // V8_SHARED | 152 #endif // V8_SHARED |
150 | 153 |
151 | 154 |
152 } // namespace v8 | 155 } // namespace v8 |
OLD | NEW |