From 9d235c9dd7d28401d20124ce3f0e7fb83c891433 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Wed, 14 Sep 2011 11:05:07 +0000 Subject: [PATCH] Fixed broken readline console history. Review URL: http://codereview.chromium.org/7888035 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9272 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8.cc | 14 ++++++++------ src/d8.h | 49 +++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/d8.cc b/src/d8.cc index a025299..87fa50f 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -117,6 +117,7 @@ CounterCollection Shell::local_counters_; CounterCollection* Shell::counters_ = &local_counters_; i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); Persistent Shell::utility_context_; +LineEditor* Shell::console = NULL; #endif // V8_SHARED Persistent Shell::evaluation_context_; @@ -791,6 +792,7 @@ void Shell::Exit(int exit_code) { #ifndef V8_SHARED void Shell::OnExit() { + console->Close(); if (i::FLAG_dump_counters) { printf("+----------------------------------------+-------------+\n"); printf("| Name | Value |\n"); @@ -895,20 +897,20 @@ void Shell::RunShell() { HandleScope outer_scope; Handle name = String::New("(d8)"); #ifndef V8_SHARED - LineEditor* editor = LineEditor::Get(); - printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); + console = LineEditor::Get(); + printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); if (i::FLAG_debugger) { printf("JavaScript debugger enabled\n"); } - editor->Open(); + console->Open(); while (true) { - i::SmartArrayPointer input = editor->Prompt(Shell::kPrompt); + i::SmartArrayPointer input = console->Prompt(Shell::kPrompt); if (input.is_empty()) break; - editor->AddHistory(*input); + console->AddHistory(*input); HandleScope inner_scope; ExecuteString(String::New(*input), name, true, true); } - editor->Close(); + console->Close(); #else printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); static const int kBufferSize = 256; diff --git a/src/d8.h b/src/d8.h index c062808..2d96d34 100644 --- a/src/d8.h +++ b/src/d8.h @@ -1,4 +1,4 @@ -// Copyright 2009 the V8 project authors. All rights reserved. +// Copyright 2011 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -116,6 +116,29 @@ class CounterMap { #endif // V8_SHARED +#ifndef V8_SHARED +class LineEditor { + public: + enum Type { DUMB = 0, READLINE = 1 }; + LineEditor(Type type, const char* name); + virtual ~LineEditor() { } + + virtual i::SmartArrayPointer Prompt(const char* prompt) = 0; + virtual bool Open() { return true; } + virtual bool Close() { return true; } + virtual void AddHistory(const char* str) { } + + const char* name() { return name_; } + static LineEditor* Get(); + private: + Type type_; + const char* name_; + LineEditor* next_; + static LineEditor* first_; +}; +#endif // V8_SHARED + + class SourceGroup { public: SourceGroup() : @@ -313,6 +336,7 @@ class Shell : public i::AllStatic { static void AddOSMethods(Handle os_template); #ifndef V8_SHARED static const char* kHistoryFileName; + static LineEditor* console; #endif // V8_SHARED static const char* kPrompt; static ShellOptions options; @@ -343,29 +367,6 @@ class Shell : public i::AllStatic { }; -#ifndef V8_SHARED -class LineEditor { - public: - enum Type { DUMB = 0, READLINE = 1 }; - LineEditor(Type type, const char* name); - virtual ~LineEditor() { } - - virtual i::SmartArrayPointer Prompt(const char* prompt) = 0; - virtual bool Open() { return true; } - virtual bool Close() { return true; } - virtual void AddHistory(const char* str) { } - - const char* name() { return name_; } - static LineEditor* Get(); - private: - Type type_; - const char* name_; - LineEditor* next_; - static LineEditor* first_; -}; -#endif // V8_SHARED - - } // namespace v8 -- 2.7.4