OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 char** result = completion_matches(text, CompletionGenerator); | 96 char** result = completion_matches(text, CompletionGenerator); |
97 rl_attempted_completion_over = true; | 97 rl_attempted_completion_over = true; |
98 return result; | 98 return result; |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { | 102 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { |
103 static unsigned current_index; | 103 static unsigned current_index; |
104 static Persistent<Array> current_completions; | 104 static Persistent<Array> current_completions; |
105 if (state == 0) { | 105 if (state == 0) { |
106 i::SmartPointer<char> full_text(i::OS::StrNDup(rl_line_buffer, rl_point)); | 106 i::SmartPointer<char> full_text(i::StrNDup(rl_line_buffer, rl_point)); |
107 HandleScope scope; | 107 HandleScope scope; |
108 Handle<Array> completions = | 108 Handle<Array> completions = |
109 Shell::GetCompletions(String::New(text), String::New(*full_text)); | 109 Shell::GetCompletions(String::New(text), String::New(*full_text)); |
110 current_completions = Persistent<Array>::New(completions); | 110 current_completions = Persistent<Array>::New(completions); |
111 current_index = 0; | 111 current_index = 0; |
112 } | 112 } |
113 if (current_index < current_completions->Length()) { | 113 if (current_index < current_completions->Length()) { |
114 HandleScope scope; | 114 HandleScope scope; |
115 Handle<Integer> index = Integer::New(current_index); | 115 Handle<Integer> index = Integer::New(current_index); |
116 Handle<Value> str_obj = current_completions->Get(index); | 116 Handle<Value> str_obj = current_completions->Get(index); |
117 current_index++; | 117 current_index++; |
118 String::Utf8Value str(str_obj); | 118 String::Utf8Value str(str_obj); |
119 return strdup(*str); | 119 return strdup(*str); |
120 } else { | 120 } else { |
121 current_completions.Dispose(); | 121 current_completions.Dispose(); |
122 current_completions.Clear(); | 122 current_completions.Clear(); |
123 return NULL; | 123 return NULL; |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 } // namespace v8 | 128 } // namespace v8 |
OLD | NEW |