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

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

Issue 11776017: Enable readline on d8 while building a shared lib. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/d8.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
29 #include <cstdio> // NOLINT 28 #include <cstdio> // NOLINT
29 #include <string.h> // NOLINT
30 #include <readline/readline.h> // NOLINT 30 #include <readline/readline.h> // NOLINT
31 #include <readline/history.h> // NOLINT 31 #include <readline/history.h> // NOLINT
32 32
33 // The readline includes leaves RETURN defined which breaks V8 compilation. 33 // The readline includes leaves RETURN defined which breaks V8 compilation.
34 #undef RETURN 34 #undef RETURN
35 35
36 #include "d8.h" 36 #include "d8.h"
37 37
38
39 // There are incompatibilities between different versions and different 38 // There are incompatibilities between different versions and different
40 // implementations of readline. This smooths out one known incompatibility. 39 // implementations of readline. This smooths out one known incompatibility.
41 #if RL_READLINE_VERSION >= 0x0500 40 #if RL_READLINE_VERSION >= 0x0500
42 #define completion_matches rl_completion_matches 41 #define completion_matches rl_completion_matches
43 #endif 42 #endif
44 43
45 44
46 namespace v8 { 45 namespace v8 {
47 46
48 47
49 class ReadLineEditor: public LineEditor { 48 class ReadLineEditor: public LineEditor {
50 public: 49 public:
51 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } 50 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
52 virtual Handle<String> Prompt(const char* prompt); 51 virtual Handle<String> Prompt(const char* prompt);
53 virtual bool Open(); 52 virtual bool Open();
54 virtual bool Close(); 53 virtual bool Close();
55 virtual void AddHistory(const char* str); 54 virtual void AddHistory(const char* str);
56 55
57 static const char* kHistoryFileName; 56 static const char* kHistoryFileName;
58 static const int kMaxHistoryEntries; 57 static const int kMaxHistoryEntries;
59 58
60 private: 59 private:
60 #ifndef V8_SHARED
61 static char** AttemptedCompletion(const char* text, int start, int end); 61 static char** AttemptedCompletion(const char* text, int start, int end);
62 static char* CompletionGenerator(const char* text, int state); 62 static char* CompletionGenerator(const char* text, int state);
63 #endif // V8_SHARED
63 static char kWordBreakCharacters[]; 64 static char kWordBreakCharacters[];
64 }; 65 };
65 66
66 67
67 static ReadLineEditor read_line_editor; 68 static ReadLineEditor read_line_editor;
68 char ReadLineEditor::kWordBreakCharacters[] = {' ', '\t', '\n', '"', 69 char ReadLineEditor::kWordBreakCharacters[] = {' ', '\t', '\n', '"',
69 '\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(', 70 '\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(',
70 '\0'}; 71 '\0'};
71 72
72 73
73 const char* ReadLineEditor::kHistoryFileName = ".d8_history"; 74 const char* ReadLineEditor::kHistoryFileName = ".d8_history";
74 const int ReadLineEditor::kMaxHistoryEntries = 1000; 75 const int ReadLineEditor::kMaxHistoryEntries = 1000;
75 76
76 77
77 bool ReadLineEditor::Open() { 78 bool ReadLineEditor::Open() {
78 rl_initialize(); 79 rl_initialize();
80
81 #ifdef V8_SHARED
82 // Don't do completion on shared library mode
83 // http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC24
84 rl_bind_key('\t', rl_insert);
85 #else
79 rl_attempted_completion_function = AttemptedCompletion; 86 rl_attempted_completion_function = AttemptedCompletion;
87 #endif // V8_SHARED
88
80 rl_completer_word_break_characters = kWordBreakCharacters; 89 rl_completer_word_break_characters = kWordBreakCharacters;
81 rl_bind_key('\t', rl_complete); 90 rl_bind_key('\t', rl_complete);
82 using_history(); 91 using_history();
83 stifle_history(kMaxHistoryEntries); 92 stifle_history(kMaxHistoryEntries);
84 return read_history(kHistoryFileName) == 0; 93 return read_history(kHistoryFileName) == 0;
85 } 94 }
86 95
87 96
88 bool ReadLineEditor::Close() { 97 bool ReadLineEditor::Close() {
89 return write_history(kHistoryFileName) == 0; 98 return write_history(kHistoryFileName) == 0;
(...skipping 25 matching lines...) Expand all
115 if (strcmp(current_history()->line, str) == 0) { 124 if (strcmp(current_history()->line, str) == 0) {
116 remove_history(where_history()); 125 remove_history(where_history());
117 break; 126 break;
118 } 127 }
119 } while (previous_history()); 128 } while (previous_history());
120 } 129 }
121 add_history(str); 130 add_history(str);
122 } 131 }
123 132
124 133
134 #ifndef V8_SHARED
125 char** ReadLineEditor::AttemptedCompletion(const char* text, 135 char** ReadLineEditor::AttemptedCompletion(const char* text,
126 int start, 136 int start,
127 int end) { 137 int end) {
128 char** result = completion_matches(text, CompletionGenerator); 138 char** result = completion_matches(text, CompletionGenerator);
129 rl_attempted_completion_over = true; 139 rl_attempted_completion_over = true;
130 return result; 140 return result;
131 } 141 }
132 142
133 143
134 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { 144 char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
(...skipping 13 matching lines...) Expand all
148 Handle<Value> str_obj = current_completions->Get(index); 158 Handle<Value> str_obj = current_completions->Get(index);
149 current_index++; 159 current_index++;
150 String::Utf8Value str(str_obj); 160 String::Utf8Value str(str_obj);
151 return strdup(*str); 161 return strdup(*str);
152 } else { 162 } else {
153 current_completions.Dispose(); 163 current_completions.Dispose();
154 current_completions.Clear(); 164 current_completions.Clear();
155 return NULL; 165 return NULL;
156 } 166 }
157 } 167 }
168 #endif // V8_SHARED
158 169
159 170
160 } // namespace v8 171 } // namespace v8
OLDNEW
« no previous file with comments | « src/d8.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698