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.cc

Issue 7885026: Fixing d8's broken readline history. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed a presubmit issue. 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 | Annotate | Revision Log
« no previous file with comments | « src/d8.h ('k') | src/d8-readline.cc » ('j') | src/d8-readline.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #ifndef ASSERT 63 #ifndef ASSERT
64 #define ASSERT(condition) assert(condition) 64 #define ASSERT(condition) assert(condition)
65 #endif 65 #endif
66 66
67 namespace v8 { 67 namespace v8 {
68 68
69 69
70 #ifndef V8_SHARED 70 #ifndef V8_SHARED
71 LineEditor *LineEditor::first_ = NULL; 71 LineEditor *LineEditor::first_ = NULL;
72 const char* Shell::kHistoryFileName = ".d8_history"; 72 const char* Shell::kHistoryFileName = ".d8_history";
73 const int Shell::kMaxHistoryEntries = 1000;
73 74
74 75
75 LineEditor::LineEditor(Type type, const char* name) 76 LineEditor::LineEditor(Type type, const char* name)
76 : type_(type), 77 : type_(type),
77 name_(name), 78 name_(name),
78 next_(first_) { 79 next_(first_) {
79 first_ = this; 80 first_ = this;
80 } 81 }
81 82
82 83
(...skipping 27 matching lines...) Expand all
110 return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str); 111 return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str);
111 } 112 }
112 113
113 114
114 CounterMap* Shell::counter_map_; 115 CounterMap* Shell::counter_map_;
115 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 116 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
116 CounterCollection Shell::local_counters_; 117 CounterCollection Shell::local_counters_;
117 CounterCollection* Shell::counters_ = &local_counters_; 118 CounterCollection* Shell::counters_ = &local_counters_;
118 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); 119 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex());
119 Persistent<Context> Shell::utility_context_; 120 Persistent<Context> Shell::utility_context_;
121 LineEditor* Shell::console = NULL;
120 #endif // V8_SHARED 122 #endif // V8_SHARED
121 123
122 Persistent<Context> Shell::evaluation_context_; 124 Persistent<Context> Shell::evaluation_context_;
123 ShellOptions Shell::options; 125 ShellOptions Shell::options;
124 const char* Shell::kPrompt = "d8> "; 126 const char* Shell::kPrompt = "d8> ";
125 127
126 128
127 #ifndef V8_SHARED 129 #ifndef V8_SHARED
128 bool CounterMap::Match(void* key1, void* key2) { 130 bool CounterMap::Match(void* key1, void* key2) {
129 const char* name1 = reinterpret_cast<const char*>(key1); 131 const char* name1 = reinterpret_cast<const char*>(key1);
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // Use _exit instead of exit to avoid races between isolate 786 // Use _exit instead of exit to avoid races between isolate
785 // threads and static destructors. 787 // threads and static destructors.
786 fflush(stdout); 788 fflush(stdout);
787 fflush(stderr); 789 fflush(stderr);
788 _exit(exit_code); 790 _exit(exit_code);
789 } 791 }
790 792
791 793
792 #ifndef V8_SHARED 794 #ifndef V8_SHARED
793 void Shell::OnExit() { 795 void Shell::OnExit() {
796 if (console != NULL) console->Close();
794 if (i::FLAG_dump_counters) { 797 if (i::FLAG_dump_counters) {
795 printf("+----------------------------------------+-------------+\n"); 798 printf("+----------------------------------------+-------------+\n");
796 printf("| Name | Value |\n"); 799 printf("| Name | Value |\n");
797 printf("+----------------------------------------+-------------+\n"); 800 printf("+----------------------------------------+-------------+\n");
798 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 801 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
799 Counter* counter = i.CurrentValue(); 802 Counter* counter = i.CurrentValue();
800 if (counter->is_histogram()) { 803 if (counter->is_histogram()) {
801 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); 804 printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count());
802 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); 805 printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total());
803 } else { 806 } else {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return result; 891 return result;
889 } 892 }
890 893
891 894
892 void Shell::RunShell() { 895 void Shell::RunShell() {
893 Locker locker; 896 Locker locker;
894 Context::Scope context_scope(evaluation_context_); 897 Context::Scope context_scope(evaluation_context_);
895 HandleScope outer_scope; 898 HandleScope outer_scope;
896 Handle<String> name = String::New("(d8)"); 899 Handle<String> name = String::New("(d8)");
897 #ifndef V8_SHARED 900 #ifndef V8_SHARED
898 LineEditor* editor = LineEditor::Get(); 901 console = LineEditor::Get();
899 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); 902 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
900 if (i::FLAG_debugger) { 903 if (i::FLAG_debugger) {
901 printf("JavaScript debugger enabled\n"); 904 printf("JavaScript debugger enabled\n");
902 } 905 }
903 editor->Open(); 906 console->Open();
904 while (true) { 907 while (true) {
905 i::SmartArrayPointer<char> input = editor->Prompt(Shell::kPrompt); 908 i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt);
906 if (input.is_empty()) break; 909 if (input.is_empty()) break;
907 editor->AddHistory(*input); 910 console->AddHistory(*input);
908 HandleScope inner_scope; 911 HandleScope inner_scope;
909 ExecuteString(String::New(*input), name, true, true); 912 ExecuteString(String::New(*input), name, true, true);
910 } 913 }
911 editor->Close();
912 #else 914 #else
913 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); 915 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion());
914 static const int kBufferSize = 256; 916 static const int kBufferSize = 256;
915 while (true) { 917 while (true) {
916 char buffer[kBufferSize]; 918 char buffer[kBufferSize];
917 printf("%s", Shell::kPrompt); 919 printf("%s", Shell::kPrompt);
918 if (fgets(buffer, kBufferSize, stdin) == NULL) break; 920 if (fgets(buffer, kBufferSize, stdin) == NULL) break;
919 HandleScope inner_scope; 921 HandleScope inner_scope;
920 ExecuteString(String::New(buffer), name, true, true); 922 ExecuteString(String::New(buffer), name, true, true);
921 } 923 }
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 } 1347 }
1346 1348
1347 } // namespace v8 1349 } // namespace v8
1348 1350
1349 1351
1350 #ifndef GOOGLE3 1352 #ifndef GOOGLE3
1351 int main(int argc, char* argv[]) { 1353 int main(int argc, char* argv[]) {
1352 return v8::Shell::Main(argc, argv); 1354 return v8::Shell::Main(argc, argv);
1353 } 1355 }
1354 #endif 1356 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/d8-readline.cc » ('j') | src/d8-readline.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698