Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 | 
| 80 i::SmartPointer<char> DumbLineEditor::Prompt(const char* prompt) { | 80 i::SmartPointer<char> DumbLineEditor::Prompt(const char* prompt) { | 
| 81 static const int kBufferSize = 256; | 81 static const int kBufferSize = 256; | 
| 82 char buffer[kBufferSize]; | 82 char buffer[kBufferSize]; | 
| 83 printf("%s", prompt); | 83 printf("%s", prompt); | 
| 84 char* str = fgets(buffer, kBufferSize, stdin); | 84 char* str = fgets(buffer, kBufferSize, stdin); | 
| 85 return i::SmartPointer<char>(str ? i::StrDup(str) : str); | 85 return i::SmartPointer<char>(str ? i::StrDup(str) : str); | 
| 86 } | 86 } | 
| 87 | 87 | 
| 88 | 88 | 
| 89 Shell::CounterMap Shell::counter_map_; | 89 CounterMap* Shell::counter_map_; | 
| 90 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 90 i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; | 
| 91 CounterCollection Shell::local_counters_; | 91 CounterCollection Shell::local_counters_; | 
| 92 CounterCollection* Shell::counters_ = &local_counters_; | 92 CounterCollection* Shell::counters_ = &local_counters_; | 
| 93 Persistent<Context> Shell::utility_context_; | 93 Persistent<Context> Shell::utility_context_; | 
| 94 Persistent<Context> Shell::evaluation_context_; | 94 Persistent<Context> Shell::evaluation_context_; | 
| 95 | 95 | 
| 96 | 96 | 
| 97 bool CounterMap::Match(void* key1, void* key2) { | |
| 98 const char* name1 = reinterpret_cast<const char*>(key1); | |
| 99 const char* name2 = reinterpret_cast<const char*>(key2); | |
| 100 return !strcmp(name1, name2); | |
| 
 
Kevin Millikin (Chromium)
2009/03/24 13:29:30
return strcmp(name1, name2) == 0; maybe?
 
 | |
| 101 } | |
| 102 | |
| 103 | |
| 97 // Converts a V8 value to a C string. | 104 // Converts a V8 value to a C string. | 
| 98 const char* ToCString(const v8::String::Utf8Value& value) { | 105 const char* ToCString(const v8::String::Utf8Value& value) { | 
| 99 return *value ? *value : "<string conversion failed>"; | 106 return *value ? *value : "<string conversion failed>"; | 
| 100 } | 107 } | 
| 101 | 108 | 
| 102 | 109 | 
| 103 // Executes a string within the current v8 context. | 110 // Executes a string within the current v8 context. | 
| 104 bool Shell::ExecuteString(Handle<String> source, | 111 bool Shell::ExecuteString(Handle<String> source, | 
| 105 Handle<Value> name, | 112 Handle<Value> name, | 
| 106 bool print_result, | 113 bool print_result, | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 NULL : counters_file_->memory(); | 298 NULL : counters_file_->memory(); | 
| 292 if (memory == NULL) { | 299 if (memory == NULL) { | 
| 293 printf("Could not map counters file %s\n", name); | 300 printf("Could not map counters file %s\n", name); | 
| 294 exit(1); | 301 exit(1); | 
| 295 } | 302 } | 
| 296 counters_ = static_cast<CounterCollection*>(memory); | 303 counters_ = static_cast<CounterCollection*>(memory); | 
| 297 V8::SetCounterFunction(LookupCounter); | 304 V8::SetCounterFunction(LookupCounter); | 
| 298 } | 305 } | 
| 299 | 306 | 
| 300 | 307 | 
| 308 int CounterMap::Hash(const char* name) { | |
| 309 int h = 0; | |
| 310 int c; | |
| 311 while ((c = *name++) != 0) { | |
| 312 h += h << 5; | |
| 313 h += c; | |
| 314 } | |
| 315 return h; | |
| 316 } | |
| 317 | |
| 318 | |
| 301 int* Shell::LookupCounter(const char* name) { | 319 int* Shell::LookupCounter(const char* name) { | 
| 302 CounterMap::iterator item = counter_map_.find(name); | 320 Counter* counter = counter_map_->Lookup(name); | 
| 303 if (item != counter_map_.end()) { | 321 if (counter != NULL) { | 
| 304 Counter* result = (*item).second; | 322 return counter->ptr(); | 
| 305 return result->ptr(); | |
| 306 } | 323 } | 
| 307 Counter* result = counters_->GetNextCounter(); | 324 Counter* result = counters_->GetNextCounter(); | 
| 308 if (result == NULL) return NULL; | 325 if (result == NULL) return NULL; | 
| 309 counter_map_[name] = result; | 326 counter_map_->Set(name, result); | 
| 310 return result->Bind(name); | 327 return result->Bind(name); | 
| 311 } | 328 } | 
| 312 | 329 | 
| 313 | 330 | 
| 314 void Shell::Initialize() { | 331 void Shell::Initialize() { | 
| 332 Shell::counter_map_ = new CounterMap(); | |
| 315 // Set up counters | 333 // Set up counters | 
| 316 if (i::FLAG_map_counters != NULL) | 334 if (i::FLAG_map_counters != NULL) | 
| 317 MapCounters(i::FLAG_map_counters); | 335 MapCounters(i::FLAG_map_counters); | 
| 318 if (i::FLAG_dump_counters) | 336 if (i::FLAG_dump_counters) | 
| 319 V8::SetCounterFunction(LookupCounter); | 337 V8::SetCounterFunction(LookupCounter); | 
| 320 // Initialize the global objects | 338 // Initialize the global objects | 
| 321 HandleScope scope; | 339 HandleScope scope; | 
| 322 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 340 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 
| 323 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 341 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 
| 324 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 342 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 // Set the security token of the debug context to allow access. | 393 // Set the security token of the debug context to allow access. | 
| 376 i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); | 394 i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); | 
| 377 } | 395 } | 
| 378 | 396 | 
| 379 | 397 | 
| 380 void Shell::OnExit() { | 398 void Shell::OnExit() { | 
| 381 if (i::FLAG_dump_counters) { | 399 if (i::FLAG_dump_counters) { | 
| 382 ::printf("+----------------------------------------+-------------+\n"); | 400 ::printf("+----------------------------------------+-------------+\n"); | 
| 383 ::printf("| Name | Value |\n"); | 401 ::printf("| Name | Value |\n"); | 
| 384 ::printf("+----------------------------------------+-------------+\n"); | 402 ::printf("+----------------------------------------+-------------+\n"); | 
| 385 for (CounterMap::iterator i = counter_map_.begin(); | 403 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 
| 386 i != counter_map_.end(); | 404 Counter* counter = i.CurrentValue(); | 
| 387 i++) { | 405 ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->value()); | 
| 388 Counter* counter = (*i).second; | |
| 389 ::printf("| %-38s | %11i |\n", (*i).first, counter->value()); | |
| 390 } | 406 } | 
| 391 ::printf("+----------------------------------------+-------------+\n"); | 407 ::printf("+----------------------------------------+-------------+\n"); | 
| 392 } | 408 } | 
| 393 if (counters_file_ != NULL) | 409 if (counters_file_ != NULL) | 
| 394 delete counters_file_; | 410 delete counters_file_; | 
| 395 } | 411 } | 
| 396 | 412 | 
| 397 | 413 | 
| 398 static char* ReadChars(const char *name, int* size_out) { | 414 static char* ReadChars(const char *name, int* size_out) { | 
| 399 v8::Unlocker unlocker; // Release the V8 lock while reading files. | 415 v8::Unlocker unlocker; // Release the V8 lock while reading files. | 
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 return 0; | 664 return 0; | 
| 649 } | 665 } | 
| 650 | 666 | 
| 651 | 667 | 
| 652 } // namespace v8 | 668 } // namespace v8 | 
| 653 | 669 | 
| 654 | 670 | 
| 655 int main(int argc, char* argv[]) { | 671 int main(int argc, char* argv[]) { | 
| 656 return v8::Shell::Main(argc, argv); | 672 return v8::Shell::Main(argc, argv); | 
| 657 } | 673 } | 
| OLD | NEW |