Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Side by Side Diff: src/d8-readline.cc

Issue 13093: Fixed d8 on leopard. (Closed)
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/platform.h » ('j') | src/platform-macos.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 28
29 #include <cstdio>
29 #include <readline/readline.h> 30 #include <readline/readline.h>
30 #include <readline/history.h> 31 #include <readline/history.h>
31 32
32 33
33 #include "d8.h" 34 #include "d8.h"
34 35
35 36
37 #if RL_READLINE_VERSION >= 0x0500
Erik Corry 2008/12/03 13:43:22 I think this deserves a comment.
38 #define completion_matches rl_completion_matches
39 #endif
40
41
36 namespace v8 { 42 namespace v8 {
37 43
38 44
39 class ReadLineEditor: public LineEditor { 45 class ReadLineEditor: public LineEditor {
40 public: 46 public:
41 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } 47 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
42 virtual i::SmartPointer<char> Prompt(const char* prompt); 48 virtual i::SmartPointer<char> Prompt(const char* prompt);
43 virtual bool Open(); 49 virtual bool Open();
44 virtual bool Close(); 50 virtual bool Close();
45 virtual void AddHistory(const char* str); 51 virtual void AddHistory(const char* str);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 84
79 85
80 void ReadLineEditor::AddHistory(const char* str) { 86 void ReadLineEditor::AddHistory(const char* str) {
81 add_history(str); 87 add_history(str);
82 } 88 }
83 89
84 90
85 char** ReadLineEditor::AttemptedCompletion(const char* text, 91 char** ReadLineEditor::AttemptedCompletion(const char* text,
86 int start, 92 int start,
87 int end) { 93 int end) {
88 char** result = rl_completion_matches(text, CompletionGenerator); 94 char** result = completion_matches(text, CompletionGenerator);
89 rl_attempted_completion_over = true; 95 rl_attempted_completion_over = true;
90 return result; 96 return result;
91 } 97 }
92 98
93 99
94 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { 100 char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
95 static unsigned current_index; 101 static unsigned current_index;
96 static Persistent<Array> current_completions; 102 static Persistent<Array> current_completions;
97 if (state == 0) { 103 if (state == 0) {
98 i::SmartPointer<char> full_text(strndup(rl_line_buffer, rl_point)); 104 i::SmartPointer<char> full_text(i::OS::StrNDup(rl_line_buffer, rl_point));
99 HandleScope scope; 105 HandleScope scope;
100 Handle<Array> completions = 106 Handle<Array> completions =
101 Shell::GetCompletions(String::New(text), String::New(*full_text)); 107 Shell::GetCompletions(String::New(text), String::New(*full_text));
102 current_completions = Persistent<Array>::New(completions); 108 current_completions = Persistent<Array>::New(completions);
103 current_index = 0; 109 current_index = 0;
104 } 110 }
105 if (current_index < current_completions->Length()) { 111 if (current_index < current_completions->Length()) {
106 HandleScope scope; 112 HandleScope scope;
107 Handle<Integer> index = Integer::New(current_index); 113 Handle<Integer> index = Integer::New(current_index);
108 Handle<Value> str_obj = current_completions->Get(index); 114 Handle<Value> str_obj = current_completions->Get(index);
109 current_index++; 115 current_index++;
110 String::Utf8Value str(str_obj); 116 String::Utf8Value str(str_obj);
111 return strdup(*str); 117 return strdup(*str);
112 } else { 118 } else {
113 current_completions.Dispose(); 119 current_completions.Dispose();
114 current_completions.Clear(); 120 current_completions.Clear();
115 return NULL; 121 return NULL;
116 } 122 }
117 } 123 }
118 124
119 125
120 } // namespace v8 126 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/platform.h » ('j') | src/platform-macos.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698