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

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

Issue 7860011: Rename SmartPointer to SmartArrayPointer. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: rebase it again to get more fixes Created 9 years, 3 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
« no previous file with comments | « src/d8-debug.cc ('k') | src/debug-agent.h » ('j') | no next file with comments »
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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #define completion_matches rl_completion_matches 42 #define completion_matches rl_completion_matches
43 #endif 43 #endif
44 44
45 45
46 namespace v8 { 46 namespace v8 {
47 47
48 48
49 class ReadLineEditor: public LineEditor { 49 class ReadLineEditor: public LineEditor {
50 public: 50 public:
51 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } 51 ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
52 virtual i::SmartPointer<char> Prompt(const char* prompt); 52 virtual i::SmartArrayPointer<char> Prompt(const char* prompt);
53 virtual bool Open(); 53 virtual bool Open();
54 virtual bool Close(); 54 virtual bool Close();
55 virtual void AddHistory(const char* str); 55 virtual void AddHistory(const char* str);
56 private: 56 private:
57 static char** AttemptedCompletion(const char* text, int start, int end); 57 static char** AttemptedCompletion(const char* text, int start, int end);
58 static char* CompletionGenerator(const char* text, int state); 58 static char* CompletionGenerator(const char* text, int state);
59 static char kWordBreakCharacters[]; 59 static char kWordBreakCharacters[];
60 }; 60 };
61 61
62 62
(...skipping 11 matching lines...) Expand all
74 using_history(); 74 using_history();
75 return read_history(Shell::kHistoryFileName) == 0; 75 return read_history(Shell::kHistoryFileName) == 0;
76 } 76 }
77 77
78 78
79 bool ReadLineEditor::Close() { 79 bool ReadLineEditor::Close() {
80 return write_history(Shell::kHistoryFileName) == 0; 80 return write_history(Shell::kHistoryFileName) == 0;
81 } 81 }
82 82
83 83
84 i::SmartPointer<char> ReadLineEditor::Prompt(const char* prompt) { 84 i::SmartArrayPointer<char> ReadLineEditor::Prompt(const char* prompt) {
85 char* result = readline(prompt); 85 char* result = readline(prompt);
86 return i::SmartPointer<char>(result); 86 return i::SmartArrayPointer<char>(result);
87 } 87 }
88 88
89 89
90 void ReadLineEditor::AddHistory(const char* str) { 90 void ReadLineEditor::AddHistory(const char* str) {
91 add_history(str); 91 add_history(str);
92 } 92 }
93 93
94 94
95 char** ReadLineEditor::AttemptedCompletion(const char* text, 95 char** ReadLineEditor::AttemptedCompletion(const char* text,
96 int start, 96 int start,
97 int end) { 97 int end) {
98 char** result = completion_matches(text, CompletionGenerator); 98 char** result = completion_matches(text, CompletionGenerator);
99 rl_attempted_completion_over = true; 99 rl_attempted_completion_over = true;
100 return result; 100 return result;
101 } 101 }
102 102
103 103
104 char* ReadLineEditor::CompletionGenerator(const char* text, int state) { 104 char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
105 static unsigned current_index; 105 static unsigned current_index;
106 static Persistent<Array> current_completions; 106 static Persistent<Array> current_completions;
107 if (state == 0) { 107 if (state == 0) {
108 i::SmartPointer<char> full_text(i::StrNDup(rl_line_buffer, rl_point)); 108 i::SmartArrayPointer<char> full_text(i::StrNDup(rl_line_buffer, rl_point));
109 HandleScope scope; 109 HandleScope scope;
110 Handle<Array> completions = 110 Handle<Array> completions =
111 Shell::GetCompletions(String::New(text), String::New(*full_text)); 111 Shell::GetCompletions(String::New(text), String::New(*full_text));
112 current_completions = Persistent<Array>::New(completions); 112 current_completions = Persistent<Array>::New(completions);
113 current_index = 0; 113 current_index = 0;
114 } 114 }
115 if (current_index < current_completions->Length()) { 115 if (current_index < current_completions->Length()) {
116 HandleScope scope; 116 HandleScope scope;
117 Handle<Integer> index = Integer::New(current_index); 117 Handle<Integer> index = Integer::New(current_index);
118 Handle<Value> str_obj = current_completions->Get(index); 118 Handle<Value> str_obj = current_completions->Get(index);
119 current_index++; 119 current_index++;
120 String::Utf8Value str(str_obj); 120 String::Utf8Value str(str_obj);
121 return strdup(*str); 121 return strdup(*str);
122 } else { 122 } else {
123 current_completions.Dispose(); 123 current_completions.Dispose();
124 current_completions.Clear(); 124 current_completions.Clear();
125 return NULL; 125 return NULL;
126 } 126 }
127 } 127 }
128 128
129 129
130 } // namespace v8 130 } // namespace v8
OLDNEW
« no previous file with comments | « src/d8-debug.cc ('k') | src/debug-agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698