From 14ed983753b62844bb29e6ac92a36b1b434f0ee6 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 8 Jan 2013 15:24:17 +0000 Subject: [PATCH] Enable readline on d8 while building a shared lib. This patch enables readline on d8 except for completion support. It sould be useful enough for history and line editing. This is related to V8's issue 1781 (http://code.google.com/p/v8/issues/detail?id=1781), not chromium's. BUG=1781 Review URL: https://chromiumcodereview.appspot.com/11776017 Patch from Luis Reis . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13333 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8-readline.cc | 15 +++++++++++++-- src/d8.cc | 12 ++++++------ src/d8.gyp | 8 ++++---- src/d8.h | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/d8-readline.cc b/src/d8-readline.cc index ed7721c..8989263 100644 --- a/src/d8-readline.cc +++ b/src/d8-readline.cc @@ -25,8 +25,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include // NOLINT +#include // NOLINT #include // NOLINT #include // NOLINT @@ -35,7 +35,6 @@ #include "d8.h" - // There are incompatibilities between different versions and different // implementations of readline. This smooths out one known incompatibility. #if RL_READLINE_VERSION >= 0x0500 @@ -58,8 +57,10 @@ class ReadLineEditor: public LineEditor { static const int kMaxHistoryEntries; private: +#ifndef V8_SHARED static char** AttemptedCompletion(const char* text, int start, int end); static char* CompletionGenerator(const char* text, int state); +#endif // V8_SHARED static char kWordBreakCharacters[]; }; @@ -76,7 +77,15 @@ const int ReadLineEditor::kMaxHistoryEntries = 1000; bool ReadLineEditor::Open() { rl_initialize(); + +#ifdef V8_SHARED + // Don't do completion on shared library mode + // http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC24 + rl_bind_key('\t', rl_insert); +#else rl_attempted_completion_function = AttemptedCompletion; +#endif // V8_SHARED + rl_completer_word_break_characters = kWordBreakCharacters; rl_bind_key('\t', rl_complete); using_history(); @@ -122,6 +131,7 @@ void ReadLineEditor::AddHistory(const char* str) { } +#ifndef V8_SHARED char** ReadLineEditor::AttemptedCompletion(const char* text, int start, int end) { @@ -155,6 +165,7 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { return NULL; } } +#endif // V8_SHARED } // namespace v8 diff --git a/src/d8.cc b/src/d8.cc index 83e2fc5..5361869 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -889,9 +889,7 @@ Handle Shell::Yield(const Arguments& args) { Handle Shell::Quit(const Arguments& args) { int exit_code = args[0]->Int32Value(); -#ifndef V8_SHARED OnExit(); -#endif // V8_SHARED exit(exit_code); return Undefined(); } @@ -1341,9 +1339,13 @@ int CompareKeys(const void* a, const void* b) { return strcmp(static_cast(a)->key, static_cast(b)->key); } +#endif // V8_SHARED void Shell::OnExit() { + LineEditor* line_editor = LineEditor::Get(); + if (line_editor) line_editor->Close(); +#ifndef V8_SHARED if (i::FLAG_dump_counters) { int number_of_counters = 0; for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { @@ -1378,8 +1380,9 @@ void Shell::OnExit() { } delete counters_file_; delete counter_map_; -} #endif // V8_SHARED +} + static FILE* FOpen(const char* path, const char* mode) { @@ -1504,7 +1507,6 @@ void Shell::RunShell(Isolate* isolate) { ExecuteString(input, name, true, true); } printf("\n"); - console->Close(); } @@ -1955,9 +1957,7 @@ int Shell::Main(int argc, char* argv[]) { } V8::Dispose(); -#ifndef V8_SHARED OnExit(); -#endif // V8_SHARED return result; } diff --git a/src/d8.gyp b/src/d8.gyp index a8361e6..cce8f2a 100644 --- a/src/d8.gyp +++ b/src/d8.gyp @@ -45,6 +45,10 @@ 'd8.cc', ], 'conditions': [ + [ 'console=="readline"', { + 'libraries': [ '-lreadline', ], + 'sources': [ 'd8-readline.cc' ], + }], [ 'component!="shared_library"', { 'sources': [ 'd8-debug.cc', '<(SHARED_INTERMEDIATE_DIR)/d8-js.cc', ], 'conditions': [ @@ -57,10 +61,6 @@ 'd8_js2c', ], }], - [ 'console=="readline"', { - 'libraries': [ '-lreadline', ], - 'sources': [ 'd8-readline.cc' ], - }], ['(OS=="linux" or OS=="mac" or OS=="freebsd" or OS=="netbsd" \ or OS=="openbsd" or OS=="solaris" or OS=="android")', { 'sources': [ 'd8-posix.cc', ] diff --git a/src/d8.h b/src/d8.h index 161c653..07699e8 100644 --- a/src/d8.h +++ b/src/d8.h @@ -277,11 +277,11 @@ class Shell : public i::AllStatic { static int RunMain(Isolate* isolate, int argc, char* argv[]); static int Main(int argc, char* argv[]); static void Exit(int exit_code); + static void OnExit(); #ifndef V8_SHARED static Handle GetCompletions(Handle text, Handle full); - static void OnExit(); static int* LookupCounter(const char* name); static void* CreateHistogram(const char* name, int min, -- 2.7.4