Commit 14ed9837 authored by yangguo@chromium.org's avatar yangguo@chromium.org

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 <luis.m.reis@gmail.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13333 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c386538c
......@@ -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 <cstdio> // NOLINT
#include <string.h> // NOLINT
#include <readline/readline.h> // NOLINT
#include <readline/history.h> // 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
......@@ -889,9 +889,7 @@ Handle<Value> Shell::Yield(const Arguments& args) {
Handle<Value> 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<const CounterAndKey*>(a)->key,
static_cast<const CounterAndKey*>(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;
}
......
......@@ -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', ]
......
......@@ -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<Array> GetCompletions(Handle<String> text,
Handle<String> full);
static void OnExit();
static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name,
int min,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment