Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/d8.cc

Issue 1250223002: Remove readline support from d8. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « src/d8.h ('k') | src/d8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 int realm_switch_; 160 int realm_switch_;
161 Global<Context>* realms_; 161 Global<Context>* realms_;
162 Global<Value> realm_shared_; 162 Global<Value> realm_shared_;
163 163
164 int RealmIndexOrThrow(const v8::FunctionCallbackInfo<v8::Value>& args, 164 int RealmIndexOrThrow(const v8::FunctionCallbackInfo<v8::Value>& args,
165 int arg_offset); 165 int arg_offset);
166 int RealmFind(Local<Context> context); 166 int RealmFind(Local<Context> context);
167 }; 167 };
168 168
169 169
170 LineEditor *LineEditor::current_ = NULL;
171
172
173 LineEditor::LineEditor(Type type, const char* name)
174 : type_(type), name_(name) {
175 if (current_ == NULL || current_->type_ < type) current_ = this;
176 }
177
178
179 class DumbLineEditor: public LineEditor {
180 public:
181 explicit DumbLineEditor(Isolate* isolate)
182 : LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { }
183 virtual Local<String> Prompt(const char* prompt);
184
185 private:
186 Isolate* isolate_;
187 };
188
189
190 Local<String> DumbLineEditor::Prompt(const char* prompt) {
191 printf("%s", prompt);
192 #if defined(__native_client__)
193 // Native Client libc is used to being embedded in Chrome and
194 // has trouble recognizing when to flush.
195 fflush(stdout);
196 #endif
197 return Shell::ReadFromStdin(isolate_);
198 }
199
200
201 #ifndef V8_SHARED 170 #ifndef V8_SHARED
202 CounterMap* Shell::counter_map_; 171 CounterMap* Shell::counter_map_;
203 base::OS::MemoryMappedFile* Shell::counters_file_ = NULL; 172 base::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
204 CounterCollection Shell::local_counters_; 173 CounterCollection Shell::local_counters_;
205 CounterCollection* Shell::counters_ = &local_counters_; 174 CounterCollection* Shell::counters_ = &local_counters_;
206 base::LazyMutex Shell::context_mutex_; 175 base::LazyMutex Shell::context_mutex_;
207 const base::TimeTicks Shell::kInitialTicks = 176 const base::TimeTicks Shell::kInitialTicks =
208 base::TimeTicks::HighResolutionNow(); 177 base::TimeTicks::HighResolutionNow();
209 Global<Context> Shell::utility_context_; 178 Global<Context> Shell::utility_context_;
210 base::LazyMutex Shell::workers_mutex_; 179 base::LazyMutex Shell::workers_mutex_;
211 bool Shell::allow_new_workers_ = true; 180 bool Shell::allow_new_workers_ = true;
212 i::List<Worker*> Shell::workers_; 181 i::List<Worker*> Shell::workers_;
213 i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_; 182 i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_;
214 #endif // !V8_SHARED 183 #endif // !V8_SHARED
215 184
216 Global<Context> Shell::evaluation_context_; 185 Global<Context> Shell::evaluation_context_;
217 ArrayBuffer::Allocator* Shell::array_buffer_allocator; 186 ArrayBuffer::Allocator* Shell::array_buffer_allocator;
218 ShellOptions Shell::options; 187 ShellOptions Shell::options;
219 const char* Shell::kPrompt = "d8> ";
220 base::OnceType Shell::quit_once_ = V8_ONCE_INIT; 188 base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
221 189
222 #ifndef V8_SHARED 190 #ifndef V8_SHARED
223 bool CounterMap::Match(void* key1, void* key2) { 191 bool CounterMap::Match(void* key1, void* key2) {
224 const char* name1 = reinterpret_cast<const char*>(key1); 192 const char* name1 = reinterpret_cast<const char*>(key1);
225 const char* name2 = reinterpret_cast<const char*>(key2); 193 const char* name2 = reinterpret_cast<const char*>(key2);
226 return strcmp(name1, name2) == 0; 194 return strcmp(name1, name2) == 0;
227 } 195 }
228 #endif // !V8_SHARED 196 #endif // !V8_SHARED
229 197
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 880 }
913 } 881 }
914 printf("\n"); 882 printf("\n");
915 #ifndef V8_SHARED 883 #ifndef V8_SHARED
916 if (enter_context) utility_context->Exit(); 884 if (enter_context) utility_context->Exit();
917 #endif // !V8_SHARED 885 #endif // !V8_SHARED
918 } 886 }
919 887
920 888
921 #ifndef V8_SHARED 889 #ifndef V8_SHARED
922 Local<Array> Shell::GetCompletions(Isolate* isolate, Local<String> text,
923 Local<String> full) {
924 EscapableHandleScope handle_scope(isolate);
925 v8::Local<v8::Context> utility_context =
926 v8::Local<v8::Context>::New(isolate, utility_context_);
927 v8::Context::Scope context_scope(utility_context);
928 Local<Object> global = utility_context->Global();
929 Local<Value> fun = global->Get(utility_context,
930 String::NewFromUtf8(isolate, "GetCompletions",
931 NewStringType::kNormal)
932 .ToLocalChecked()).ToLocalChecked();
933 static const int kArgc = 3;
934 v8::Local<v8::Context> evaluation_context =
935 v8::Local<v8::Context>::New(isolate, evaluation_context_);
936 Local<Value> argv[kArgc] = {evaluation_context->Global(), text, full};
937 Local<Value> val = Local<Function>::Cast(fun)
938 ->Call(utility_context, global, kArgc, argv)
939 .ToLocalChecked();
940 return handle_scope.Escape(Local<Array>::Cast(val));
941 }
942
943
944 int32_t* Counter::Bind(const char* name, bool is_histogram) { 890 int32_t* Counter::Bind(const char* name, bool is_histogram) {
945 int i; 891 int i;
946 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) 892 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
947 name_[i] = static_cast<char>(name[i]); 893 name_[i] = static_cast<char>(name[i]);
948 name_[i] = '\0'; 894 name_[i] = '\0';
949 is_histogram_ = is_histogram; 895 is_histogram_ = is_histogram;
950 return ptr(); 896 return ptr();
951 } 897 }
952 898
953 899
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 }; 1224 };
1279 1225
1280 1226
1281 inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) { 1227 inline bool operator<(const CounterAndKey& lhs, const CounterAndKey& rhs) {
1282 return strcmp(lhs.key, rhs.key) < 0; 1228 return strcmp(lhs.key, rhs.key) < 0;
1283 } 1229 }
1284 #endif // !V8_SHARED 1230 #endif // !V8_SHARED
1285 1231
1286 1232
1287 void Shell::OnExit(v8::Isolate* isolate) { 1233 void Shell::OnExit(v8::Isolate* isolate) {
1288 LineEditor* line_editor = LineEditor::Get();
1289 if (line_editor) line_editor->Close();
1290 #ifndef V8_SHARED 1234 #ifndef V8_SHARED
1291 reinterpret_cast<i::Isolate*>(isolate)->DumpAndResetCompilationStats(); 1235 reinterpret_cast<i::Isolate*>(isolate)->DumpAndResetCompilationStats();
1292 if (i::FLAG_dump_counters) { 1236 if (i::FLAG_dump_counters) {
1293 int number_of_counters = 0; 1237 int number_of_counters = 0;
1294 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { 1238 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
1295 number_of_counters++; 1239 number_of_counters++;
1296 } 1240 }
1297 CounterAndKey* counters = new CounterAndKey[number_of_counters]; 1241 CounterAndKey* counters = new CounterAndKey[number_of_counters];
1298 int j = 0; 1242 int j = 0;
1299 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) { 1243 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1381
1438 void Shell::RunShell(Isolate* isolate) { 1382 void Shell::RunShell(Isolate* isolate) {
1439 HandleScope outer_scope(isolate); 1383 HandleScope outer_scope(isolate);
1440 v8::Local<v8::Context> context = 1384 v8::Local<v8::Context> context =
1441 v8::Local<v8::Context>::New(isolate, evaluation_context_); 1385 v8::Local<v8::Context>::New(isolate, evaluation_context_);
1442 v8::Context::Scope context_scope(context); 1386 v8::Context::Scope context_scope(context);
1443 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); 1387 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1444 Local<String> name = 1388 Local<String> name =
1445 String::NewFromUtf8(isolate, "(d8)", NewStringType::kNormal) 1389 String::NewFromUtf8(isolate, "(d8)", NewStringType::kNormal)
1446 .ToLocalChecked(); 1390 .ToLocalChecked();
1447 LineEditor* console = LineEditor::Get(); 1391 printf("V8 version %s\n", V8::GetVersion());
1448 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
1449 console->Open(isolate);
1450 while (true) { 1392 while (true) {
1451 HandleScope inner_scope(isolate); 1393 HandleScope inner_scope(isolate);
1452 Local<String> input = console->Prompt(Shell::kPrompt); 1394 printf(" d8>");
1395 #if defined(__native_client__)
1396 // Native Client libc is used to being embedded in Chrome and
1397 // has trouble recognizing when to flush.
1398 fflush(stdout);
1399 #endif
1400 Local<String> input = Shell::ReadFromStdin(isolate);
1453 if (input.IsEmpty()) break; 1401 if (input.IsEmpty()) break;
1454 ExecuteString(isolate, input, name, true, true); 1402 ExecuteString(isolate, input, name, true, true);
1455 } 1403 }
1456 printf("\n"); 1404 printf("\n");
1457 } 1405 }
1458 1406
1459 1407
1460 SourceGroup::~SourceGroup() { 1408 SourceGroup::~SourceGroup() {
1461 #ifndef V8_SHARED 1409 #ifndef V8_SHARED
1462 delete thread_; 1410 delete thread_;
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 base::SysInfo::AmountOfVirtualMemory()); 2375 base::SysInfo::AmountOfVirtualMemory());
2428 2376
2429 Shell::counter_map_ = new CounterMap(); 2377 Shell::counter_map_ = new CounterMap();
2430 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { 2378 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) {
2431 create_params.counter_lookup_callback = LookupCounter; 2379 create_params.counter_lookup_callback = LookupCounter;
2432 create_params.create_histogram_callback = CreateHistogram; 2380 create_params.create_histogram_callback = CreateHistogram;
2433 create_params.add_histogram_sample_callback = AddHistogramSample; 2381 create_params.add_histogram_sample_callback = AddHistogramSample;
2434 } 2382 }
2435 #endif 2383 #endif
2436 Isolate* isolate = Isolate::New(create_params); 2384 Isolate* isolate = Isolate::New(create_params);
2437 DumbLineEditor dumb_line_editor(isolate);
2438 { 2385 {
2439 Isolate::Scope scope(isolate); 2386 Isolate::Scope scope(isolate);
2440 Initialize(isolate); 2387 Initialize(isolate);
2441 PerIsolateData data(isolate); 2388 PerIsolateData data(isolate);
2442 2389
2443 #ifndef V8_SHARED 2390 #ifndef V8_SHARED
2444 if (options.dump_heap_constants) { 2391 if (options.dump_heap_constants) {
2445 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate)); 2392 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate));
2446 return 0; 2393 return 0;
2447 } 2394 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 } 2454 }
2508 2455
2509 } // namespace v8 2456 } // namespace v8
2510 2457
2511 2458
2512 #ifndef GOOGLE3 2459 #ifndef GOOGLE3
2513 int main(int argc, char* argv[]) { 2460 int main(int argc, char* argv[]) {
2514 return v8::Shell::Main(argc, argv); 2461 return v8::Shell::Main(argc, argv);
2515 } 2462 }
2516 #endif 2463 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/d8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698