| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 #undef DEFINE_SYMBOL_GETTER | 116 #undef DEFINE_SYMBOL_GETTER |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 Isolate* isolate_; | 119 Isolate* isolate_; |
| 120 #define DEFINE_MEMBER(name, value) Persistent<String> name##_; | 120 #define DEFINE_MEMBER(name, value) Persistent<String> name##_; |
| 121 FOR_EACH_SYMBOL(DEFINE_MEMBER) | 121 FOR_EACH_SYMBOL(DEFINE_MEMBER) |
| 122 #undef DEFINE_MEMBER | 122 #undef DEFINE_MEMBER |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 | 125 |
| 126 LineEditor *LineEditor::first_ = NULL; | 126 #ifndef USE_READLINE_CONSOLE |
| 127 | 127 |
| 128 void LineEditor::Open() { } |
| 128 | 129 |
| 129 LineEditor::LineEditor(Type type, const char* name) | 130 LineEditor::~LineEditor() { } |
| 130 : type_(type), | |
| 131 name_(name), | |
| 132 next_(first_) { | |
| 133 first_ = this; | |
| 134 } | |
| 135 | 131 |
| 132 const char* LineEditor::name() { return "dumb"; } |
| 136 | 133 |
| 137 LineEditor* LineEditor::Get() { | 134 void LineEditor::AddHistory(const char* str) { } |
| 138 LineEditor* current = first_; | |
| 139 LineEditor* best = current; | |
| 140 while (current != NULL) { | |
| 141 if (current->type_ > best->type_) | |
| 142 best = current; | |
| 143 current = current->next_; | |
| 144 } | |
| 145 return best; | |
| 146 } | |
| 147 | 135 |
| 148 | 136 Handle<String> LineEditor::Prompt(const char* prompt) { |
| 149 class DumbLineEditor: public LineEditor { | |
| 150 public: | |
| 151 explicit DumbLineEditor(Isolate* isolate) | |
| 152 : LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { } | |
| 153 virtual Handle<String> Prompt(const char* prompt); | |
| 154 private: | |
| 155 Isolate* isolate_; | |
| 156 }; | |
| 157 | |
| 158 | |
| 159 Handle<String> DumbLineEditor::Prompt(const char* prompt) { | |
| 160 printf("%s", prompt); | 137 printf("%s", prompt); |
| 161 return Shell::ReadFromStdin(isolate_); | 138 return Shell::ReadFromStdin(isolate_); |
| 162 } | 139 } |
| 163 | 140 |
| 141 #endif // USE_READLINE_CONSOLE |
| 142 |
| 164 | 143 |
| 165 #ifndef V8_SHARED | 144 #ifndef V8_SHARED |
| 166 CounterMap* Shell::counter_map_; | 145 CounterMap* Shell::counter_map_; |
| 167 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 146 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; |
| 168 CounterCollection Shell::local_counters_; | 147 CounterCollection Shell::local_counters_; |
| 169 CounterCollection* Shell::counters_ = &local_counters_; | 148 CounterCollection* Shell::counters_ = &local_counters_; |
| 170 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); | 149 i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); |
| 171 Persistent<Context> Shell::utility_context_; | 150 Persistent<Context> Shell::utility_context_; |
| 172 #endif // V8_SHARED | 151 #endif // V8_SHARED |
| 173 | 152 |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 | 1326 |
| 1348 | 1327 |
| 1349 int CompareKeys(const void* a, const void* b) { | 1328 int CompareKeys(const void* a, const void* b) { |
| 1350 return strcmp(static_cast<const CounterAndKey*>(a)->key, | 1329 return strcmp(static_cast<const CounterAndKey*>(a)->key, |
| 1351 static_cast<const CounterAndKey*>(b)->key); | 1330 static_cast<const CounterAndKey*>(b)->key); |
| 1352 } | 1331 } |
| 1353 #endif // V8_SHARED | 1332 #endif // V8_SHARED |
| 1354 | 1333 |
| 1355 | 1334 |
| 1356 void Shell::OnExit() { | 1335 void Shell::OnExit() { |
| 1357 LineEditor* line_editor = LineEditor::Get(); | |
| 1358 if (line_editor) line_editor->Close(); | |
| 1359 #ifndef V8_SHARED | 1336 #ifndef V8_SHARED |
| 1360 if (i::FLAG_dump_counters) { | 1337 if (i::FLAG_dump_counters) { |
| 1361 int number_of_counters = 0; | 1338 int number_of_counters = 0; |
| 1362 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 1339 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { |
| 1363 number_of_counters++; | 1340 number_of_counters++; |
| 1364 } | 1341 } |
| 1365 CounterAndKey* counters = new CounterAndKey[number_of_counters]; | 1342 CounterAndKey* counters = new CounterAndKey[number_of_counters]; |
| 1366 int j = 0; | 1343 int j = 0; |
| 1367 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) { | 1344 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) { |
| 1368 counters[j].counter = i.CurrentValue(); | 1345 counters[j].counter = i.CurrentValue(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 delete[] chars; | 1479 delete[] chars; |
| 1503 return result; | 1480 return result; |
| 1504 } | 1481 } |
| 1505 | 1482 |
| 1506 | 1483 |
| 1507 void Shell::RunShell(Isolate* isolate) { | 1484 void Shell::RunShell(Isolate* isolate) { |
| 1508 Locker locker(isolate); | 1485 Locker locker(isolate); |
| 1509 Context::Scope context_scope(evaluation_context_); | 1486 Context::Scope context_scope(evaluation_context_); |
| 1510 HandleScope outer_scope; | 1487 HandleScope outer_scope; |
| 1511 Handle<String> name = String::New("(d8)"); | 1488 Handle<String> name = String::New("(d8)"); |
| 1512 LineEditor* console = LineEditor::Get(); | 1489 LineEditor console(isolate); |
| 1513 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); | 1490 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console.name()); |
| 1514 console->Open(); | |
| 1515 while (true) { | 1491 while (true) { |
| 1516 HandleScope inner_scope; | 1492 HandleScope inner_scope; |
| 1517 Handle<String> input = console->Prompt(Shell::kPrompt); | 1493 Handle<String> input = console.Prompt(Shell::kPrompt); |
| 1518 if (input.IsEmpty()) break; | 1494 if (input.IsEmpty()) break; |
| 1519 ExecuteString(input, name, true, true); | 1495 ExecuteString(input, name, true, true); |
| 1520 } | 1496 } |
| 1521 printf("\n"); | 1497 printf("\n"); |
| 1522 } | 1498 } |
| 1523 | 1499 |
| 1524 | 1500 |
| 1525 #ifndef V8_SHARED | 1501 #ifndef V8_SHARED |
| 1526 class ShellThread : public i::Thread { | 1502 class ShellThread : public i::Thread { |
| 1527 public: | 1503 public: |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 } | 1882 } |
| 1907 #endif // V8_SHARED | 1883 #endif // V8_SHARED |
| 1908 return 0; | 1884 return 0; |
| 1909 } | 1885 } |
| 1910 | 1886 |
| 1911 | 1887 |
| 1912 int Shell::Main(int argc, char* argv[]) { | 1888 int Shell::Main(int argc, char* argv[]) { |
| 1913 if (!SetOptions(argc, argv)) return 1; | 1889 if (!SetOptions(argc, argv)) return 1; |
| 1914 int result = 0; | 1890 int result = 0; |
| 1915 Isolate* isolate = Isolate::GetCurrent(); | 1891 Isolate* isolate = Isolate::GetCurrent(); |
| 1916 DumbLineEditor dumb_line_editor(isolate); | |
| 1917 { | 1892 { |
| 1918 Initialize(isolate); | 1893 Initialize(isolate); |
| 1919 Symbols symbols(isolate); | 1894 Symbols symbols(isolate); |
| 1920 InitializeDebugger(isolate); | 1895 InitializeDebugger(isolate); |
| 1921 | 1896 |
| 1922 if (options.stress_opt || options.stress_deopt) { | 1897 if (options.stress_opt || options.stress_deopt) { |
| 1923 Testing::SetStressRunType(options.stress_opt | 1898 Testing::SetStressRunType(options.stress_opt |
| 1924 ? Testing::kStressTypeOpt | 1899 ? Testing::kStressTypeOpt |
| 1925 : Testing::kStressTypeDeopt); | 1900 : Testing::kStressTypeDeopt); |
| 1926 int stress_runs = Testing::GetStressRuns(); | 1901 int stress_runs = Testing::GetStressRuns(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 } | 1951 } |
| 1977 | 1952 |
| 1978 } // namespace v8 | 1953 } // namespace v8 |
| 1979 | 1954 |
| 1980 | 1955 |
| 1981 #ifndef GOOGLE3 | 1956 #ifndef GOOGLE3 |
| 1982 int main(int argc, char* argv[]) { | 1957 int main(int argc, char* argv[]) { |
| 1983 return v8::Shell::Main(argc, argv); | 1958 return v8::Shell::Main(argc, argv); |
| 1984 } | 1959 } |
| 1985 #endif | 1960 #endif |
| OLD | NEW |