 Chromium Code Reviews
 Chromium Code Reviews Issue 7219003:
  removed some unnecessary stuff from d8's initialization  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 7219003:
  removed some unnecessary stuff from d8's initialization  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| OLD | NEW | 
|---|---|
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 } | 481 } | 
| 482 | 482 | 
| 483 | 483 | 
| 484 void Shell::AddHistogramSample(void* histogram, int sample) { | 484 void Shell::AddHistogramSample(void* histogram, int sample) { | 
| 485 Counter* counter = reinterpret_cast<Counter*>(histogram); | 485 Counter* counter = reinterpret_cast<Counter*>(histogram); | 
| 486 counter->AddSample(sample); | 486 counter->AddSample(sample); | 
| 487 } | 487 } | 
| 488 | 488 | 
| 489 void Shell::InstallUtilityScript() { | 489 void Shell::InstallUtilityScript() { | 
| 490 Locker lock; | 490 Locker lock; | 
| 491 HandleScope scope; | 491 HandleScope scope; | 
| 
Søren Thygesen Gjesse
2011/06/24 11:36:09
Maybe add a comment here that when the utility con
 | |
| 492 utility_context_->SetSecurityToken(Undefined()); | |
| 493 evaluation_context_->SetSecurityToken(Undefined()); | |
| 492 Context::Scope utility_scope(utility_context_); | 494 Context::Scope utility_scope(utility_context_); | 
| 495 | |
| 496 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 497 // Install the debugger object in the utility scope | |
| 498 i::Debug* debug = i::Isolate::Current()->debug(); | |
| 499 debug->Load(); | |
| 500 i::Handle<i::JSObject> js_debug | |
| 501 = i::Handle<i::JSObject>(debug->debug_context()->global()); | |
| 502 utility_context_->Global()->Set(String::New("$debug"), | |
| 503 Utils::ToLocal(js_debug)); | |
| 504 debug->debug_context()->set_security_token(HEAP->undefined_value()); | |
| 505 #endif | |
| 506 | |
| 493 // Run the d8 shell utility script in the utility context | 507 // Run the d8 shell utility script in the utility context | 
| 494 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 508 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 
| 495 i::Vector<const char> shell_source = | 509 i::Vector<const char> shell_source = | 
| 496 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | 510 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | 
| 497 i::Vector<const char> shell_source_name = | 511 i::Vector<const char> shell_source_name = | 
| 498 i::NativesCollection<i::D8>::GetScriptName(source_index); | 512 i::NativesCollection<i::D8>::GetScriptName(source_index); | 
| 499 Handle<String> source = String::New(shell_source.start(), | 513 Handle<String> source = String::New(shell_source.start(), | 
| 500 shell_source.length()); | 514 shell_source.length()); | 
| 501 Handle<String> name = String::New(shell_source_name.start(), | 515 Handle<String> name = String::New(shell_source_name.start(), | 
| 502 shell_source_name.length()); | 516 shell_source_name.length()); | 
| 503 Handle<Script> script = Script::Compile(source, name); | 517 Handle<Script> script = Script::Compile(source, name); | 
| 504 script->Run(); | 518 script->Run(); | 
| 505 | 519 | 
| 506 // Mark the d8 shell script as native to avoid it showing up as normal source | 520 // Mark the d8 shell script as native to avoid it showing up as normal source | 
| 507 // in the debugger. | 521 // in the debugger. | 
| 508 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); | 522 i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); | 
| 509 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() | 523 i::Handle<i::Script> script_object = compiled_script->IsJSFunction() | 
| 510 ? i::Handle<i::Script>(i::Script::cast( | 524 ? i::Handle<i::Script>(i::Script::cast( | 
| 511 i::JSFunction::cast(*compiled_script)->shared()->script())) | 525 i::JSFunction::cast(*compiled_script)->shared()->script())) | 
| 512 : i::Handle<i::Script>(i::Script::cast( | 526 : i::Handle<i::Script>(i::Script::cast( | 
| 513 i::SharedFunctionInfo::cast(*compiled_script)->script())); | 527 i::SharedFunctionInfo::cast(*compiled_script)->script())); | 
| 514 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); | 528 script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); | 
| 515 } | 529 } | 
| 516 | 530 | 
| 531 | |
| 517 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 532 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 
| 518 class BZip2Decompressor : public v8::StartupDataDecompressor { | 533 class BZip2Decompressor : public v8::StartupDataDecompressor { | 
| 519 public: | 534 public: | 
| 520 virtual ~BZip2Decompressor() { } | 535 virtual ~BZip2Decompressor() { } | 
| 521 | 536 | 
| 522 protected: | 537 protected: | 
| 523 virtual int DecompressData(char* raw_data, | 538 virtual int DecompressData(char* raw_data, | 
| 524 int* raw_data_size, | 539 int* raw_data_size, | 
| 525 const char* compressed_data, | 540 const char* compressed_data, | 
| 526 int compressed_data_size) { | 541 int compressed_data_size) { | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 593 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 
| 579 #endif | 594 #endif | 
| 580 | 595 | 
| 581 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 596 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 
| 582 AddOSMethods(os_templ); | 597 AddOSMethods(os_templ); | 
| 583 global_template->Set(String::New("os"), os_templ); | 598 global_template->Set(String::New("os"), os_templ); | 
| 584 | 599 | 
| 585 return global_template; | 600 return global_template; | 
| 586 } | 601 } | 
| 587 | 602 | 
| 588 void Shell::Initialize() { | 603 | 
| 604 void Shell::Initialize(bool test_shell) { | |
| 589 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 605 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 
| 590 BZip2Decompressor startup_data_decompressor; | 606 BZip2Decompressor startup_data_decompressor; | 
| 591 int bz2_result = startup_data_decompressor.Decompress(); | 607 int bz2_result = startup_data_decompressor.Decompress(); | 
| 592 if (bz2_result != BZ_OK) { | 608 if (bz2_result != BZ_OK) { | 
| 593 fprintf(stderr, "bzip error code: %d\n", bz2_result); | 609 fprintf(stderr, "bzip error code: %d\n", bz2_result); | 
| 594 exit(1); | 610 exit(1); | 
| 595 } | 611 } | 
| 596 #endif | 612 #endif | 
| 597 | 613 | 
| 598 Shell::counter_map_ = new CounterMap(); | 614 Shell::counter_map_ = new CounterMap(); | 
| 599 // Set up counters | 615 // Set up counters | 
| 600 if (i::StrLength(i::FLAG_map_counters) != 0) | 616 if (i::StrLength(i::FLAG_map_counters) != 0) | 
| 601 MapCounters(i::FLAG_map_counters); | 617 MapCounters(i::FLAG_map_counters); | 
| 602 if (i::FLAG_dump_counters) { | 618 if (i::FLAG_dump_counters) { | 
| 603 V8::SetCounterFunction(LookupCounter); | 619 V8::SetCounterFunction(LookupCounter); | 
| 604 V8::SetCreateHistogramFunction(CreateHistogram); | 620 V8::SetCreateHistogramFunction(CreateHistogram); | 
| 605 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 621 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 
| 606 } | 622 } | 
| 607 | 623 | 
| 608 // Initialize the global objects | 624 if (test_shell && !i::FLAG_remote_debugger) return; | 
| 625 | |
| 626 Locker lock; | |
| 609 HandleScope scope; | 627 HandleScope scope; | 
| 610 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 628 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 
| 611 | |
| 612 utility_context_ = Context::New(NULL, global_template); | 629 utility_context_ = Context::New(NULL, global_template); | 
| 613 utility_context_->SetSecurityToken(Undefined()); | |
| 614 Context::Scope utility_scope(utility_context_); | |
| 615 | 630 | 
| 616 #ifdef ENABLE_DEBUGGER_SUPPORT | 631 #ifdef ENABLE_DEBUGGER_SUPPORT | 
| 617 // Install the debugger object in the utility scope | 632 // Start the debugger agent if requested. | 
| 618 i::Debug* debug = i::Isolate::Current()->debug(); | 633 if (i::FLAG_debugger_agent) { | 
| 619 debug->Load(); | 634 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 
| 620 i::Handle<i::JSObject> js_debug | 635 } | 
| 621 = i::Handle<i::JSObject>(debug->debug_context()->global()); | 636 | 
| 622 utility_context_->Global()->Set(String::New("$debug"), | 637 // Start the in-process debugger if requested. | 
| 623 Utils::ToLocal(js_debug)); | 638 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 
| 639 v8::Debug::SetDebugEventListener(HandleDebugEvent); | |
| 640 } | |
| 624 #endif | 641 #endif | 
| 625 } | 642 } | 
| 626 | 643 | 
| 627 | 644 | 
| 628 void Shell::RenewEvaluationContext() { | 645 void Shell::RenewEvaluationContext() { | 
| 629 // Initialize the global objects | 646 // Initialize the global objects | 
| 630 HandleScope scope; | 647 HandleScope scope; | 
| 631 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 648 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 
| 632 | 649 | 
| 633 // (Re-)create the evaluation context | 650 // (Re-)create the evaluation context | 
| 634 if (!evaluation_context_.IsEmpty()) { | 651 if (!evaluation_context_.IsEmpty()) { | 
| 635 evaluation_context_.Dispose(); | 652 evaluation_context_.Dispose(); | 
| 636 } | 653 } | 
| 637 evaluation_context_ = Context::New(NULL, global_template); | 654 evaluation_context_ = Context::New(NULL, global_template); | 
| 638 evaluation_context_->SetSecurityToken(Undefined()); | 655 Context::Scope utility_scope(evaluation_context_); | 
| 639 | 656 | 
| 640 Context::Scope utility_scope(utility_context_); | |
| 641 i::JSArguments js_args = i::FLAG_js_arguments; | 657 i::JSArguments js_args = i::FLAG_js_arguments; | 
| 642 i::Handle<i::FixedArray> arguments_array = | 658 i::Handle<i::FixedArray> arguments_array = | 
| 643 FACTORY->NewFixedArray(js_args.argc()); | 659 FACTORY->NewFixedArray(js_args.argc()); | 
| 644 for (int j = 0; j < js_args.argc(); j++) { | 660 for (int j = 0; j < js_args.argc(); j++) { | 
| 645 i::Handle<i::String> arg = | 661 i::Handle<i::String> arg = | 
| 646 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 662 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 
| 647 arguments_array->set(j, *arg); | 663 arguments_array->set(j, *arg); | 
| 648 } | 664 } | 
| 649 i::Handle<i::JSArray> arguments_jsarray = | 665 i::Handle<i::JSArray> arguments_jsarray = | 
| 650 FACTORY->NewJSArrayWithElements(arguments_array); | 666 FACTORY->NewJSArrayWithElements(arguments_array); | 
| 651 evaluation_context_->Global()->Set(String::New("arguments"), | 667 evaluation_context_->Global()->Set(String::New("arguments"), | 
| 652 Utils::ToLocal(arguments_jsarray)); | 668 Utils::ToLocal(arguments_jsarray)); | 
| 653 | |
| 654 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 655 i::Debug* debug = i::Isolate::Current()->debug(); | |
| 656 debug->Load(); | |
| 657 | |
| 658 // Set the security token of the debug context to allow access. | |
| 659 debug->debug_context()->set_security_token(HEAP->undefined_value()); | |
| 660 | |
| 661 // Start the debugger agent if requested. | |
| 662 if (i::FLAG_debugger_agent) { | |
| 663 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | |
| 664 } | |
| 665 | |
| 666 // Start the in-process debugger if requested. | |
| 667 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | |
| 668 v8::Debug::SetDebugEventListener(HandleDebugEvent); | |
| 669 } | |
| 670 #endif | |
| 671 } | 669 } | 
| 672 | 670 | 
| 673 | 671 | 
| 674 void Shell::OnExit() { | 672 void Shell::OnExit() { | 
| 675 if (i::FLAG_dump_counters) { | 673 if (i::FLAG_dump_counters) { | 
| 676 ::printf("+----------------------------------------+-------------+\n"); | 674 ::printf("+----------------------------------------+-------------+\n"); | 
| 677 ::printf("| Name | Value |\n"); | 675 ::printf("| Name | Value |\n"); | 
| 678 ::printf("+----------------------------------------+-------------+\n"); | 676 ::printf("+----------------------------------------+-------------+\n"); | 
| 679 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 677 for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 
| 680 Counter* counter = i.CurrentValue(); | 678 Counter* counter = i.CurrentValue(); | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 return result; | 744 return result; | 
| 747 } | 745 } | 
| 748 | 746 | 
| 749 | 747 | 
| 750 void Shell::RunShell() { | 748 void Shell::RunShell() { | 
| 751 LineEditor* editor = LineEditor::Get(); | 749 LineEditor* editor = LineEditor::Get(); | 
| 752 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); | 750 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); | 
| 753 if (i::FLAG_debugger) { | 751 if (i::FLAG_debugger) { | 
| 754 printf("JavaScript debugger enabled\n"); | 752 printf("JavaScript debugger enabled\n"); | 
| 755 } | 753 } | 
| 754 | |
| 756 editor->Open(); | 755 editor->Open(); | 
| 757 while (true) { | 756 while (true) { | 
| 758 Locker locker; | 757 Locker locker; | 
| 759 HandleScope handle_scope; | 758 HandleScope handle_scope; | 
| 760 Context::Scope context_scope(evaluation_context_); | 759 Context::Scope context_scope(evaluation_context_); | 
| 761 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); | 760 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); | 
| 762 if (input.is_empty()) | 761 if (input.is_empty()) | 
| 763 break; | 762 break; | 
| 764 editor->AddHistory(*input); | 763 editor->AddHistory(*input); | 
| 765 Handle<String> name = String::New("(d8)"); | 764 Handle<String> name = String::New("(d8)"); | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 793 // For each newline-separated line. | 792 // For each newline-separated line. | 
| 794 char* next_line = ReadLine(ptr); | 793 char* next_line = ReadLine(ptr); | 
| 795 | 794 | 
| 796 if (*ptr == '#') { | 795 if (*ptr == '#') { | 
| 797 // Skip comment lines. | 796 // Skip comment lines. | 
| 798 ptr = next_line; | 797 ptr = next_line; | 
| 799 continue; | 798 continue; | 
| 800 } | 799 } | 
| 801 | 800 | 
| 802 Persistent<Context> thread_context = Context::New(NULL, global_template); | 801 Persistent<Context> thread_context = Context::New(NULL, global_template); | 
| 803 thread_context->SetSecurityToken(Undefined()); | |
| 804 Context::Scope context_scope(thread_context); | 802 Context::Scope context_scope(thread_context); | 
| 805 | 803 | 
| 806 while ((ptr != NULL) && (*ptr != '\0')) { | 804 while ((ptr != NULL) && (*ptr != '\0')) { | 
| 807 char* filename = ptr; | 805 char* filename = ptr; | 
| 808 ptr = ReadWord(ptr); | 806 ptr = ReadWord(ptr); | 
| 809 | 807 | 
| 810 // Skip empty strings. | 808 // Skip empty strings. | 
| 811 if (strlen(filename) == 0) { | 809 if (strlen(filename) == 0) { | 
| 812 break; | 810 break; | 
| 813 } | 811 } | 
| 814 | 812 | 
| 815 Handle<String> str = Shell::ReadFile(filename); | 813 Handle<String> str = Shell::ReadFile(filename); | 
| 816 if (str.IsEmpty()) { | 814 if (str.IsEmpty()) { | 
| 817 printf("WARNING: %s not found\n", filename); | 815 printf("WARNING: %s not found\n", filename); | 
| 818 break; | 816 break; | 
| 819 } | 817 } | 
| 820 | 818 | 
| 821 Shell::ExecuteString(str, String::New(filename), false, false); | 819 Shell::ExecuteString(str, String::New(filename), false, false); | 
| 822 } | 820 } | 
| 823 | 821 | 
| 824 thread_context.Dispose(); | 822 thread_context.Dispose(); | 
| 825 ptr = next_line; | 823 ptr = next_line; | 
| 826 } | 824 } | 
| 827 } | 825 } | 
| 828 | 826 | 
| 829 int Shell::RunMain(int argc, char* argv[]) { | 827 int Shell::RunMain(int argc, char* argv[], bool* executed) { | 
| 
Yang
2011/06/23 21:45:53
Pass this flag by reference to track whether somet
 | |
| 830 // Default use preemption if threads are created. | 828 // Default use preemption if threads are created. | 
| 831 bool use_preemption = true; | 829 bool use_preemption = true; | 
| 832 | 830 | 
| 833 // Default to use lowest possible thread preemption interval to test as many | 831 // Default to use lowest possible thread preemption interval to test as many | 
| 834 // edgecases as possible. | 832 // edgecases as possible. | 
| 835 int preemption_interval = 1; | 833 int preemption_interval = 1; | 
| 836 | 834 | 
| 837 i::List<i::Thread*> threads(1); | 835 i::List<i::Thread*> threads(1); | 
| 838 | 836 | 
| 839 { | 837 { | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 864 // Ignore any -f flags for compatibility with other stand-alone | 862 // Ignore any -f flags for compatibility with other stand-alone | 
| 865 // JavaScript engines. | 863 // JavaScript engines. | 
| 866 continue; | 864 continue; | 
| 867 } else if (strncmp(str, "--", 2) == 0) { | 865 } else if (strncmp(str, "--", 2) == 0) { | 
| 868 printf("Warning: unknown flag %s.\nTry --help for options\n", str); | 866 printf("Warning: unknown flag %s.\nTry --help for options\n", str); | 
| 869 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { | 867 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { | 
| 870 // Execute argument given to -e option directly. | 868 // Execute argument given to -e option directly. | 
| 871 v8::HandleScope handle_scope; | 869 v8::HandleScope handle_scope; | 
| 872 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); | 870 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); | 
| 873 v8::Handle<v8::String> source = v8::String::New(argv[++i]); | 871 v8::Handle<v8::String> source = v8::String::New(argv[++i]); | 
| 872 (*executed) = true; | |
| 874 if (!ExecuteString(source, file_name, false, true)) { | 873 if (!ExecuteString(source, file_name, false, true)) { | 
| 875 OnExit(); | 874 OnExit(); | 
| 876 return 1; | 875 return 1; | 
| 877 } | 876 } | 
| 878 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { | 877 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { | 
| 879 int size = 0; | 878 int size = 0; | 
| 880 const char* files = ReadChars(argv[++i], &size); | 879 const char* files = ReadChars(argv[++i], &size); | 
| 881 if (files == NULL) return 1; | 880 if (files == NULL) return 1; | 
| 882 ShellThread* thread = | 881 ShellThread* thread = | 
| 883 new ShellThread(threads.length(), | 882 new ShellThread(threads.length(), | 
| 884 i::Vector<const char>(files, size)); | 883 i::Vector<const char>(files, size)); | 
| 885 thread->Start(); | 884 thread->Start(); | 
| 886 threads.Add(thread); | 885 threads.Add(thread); | 
| 886 (*executed) = true; | |
| 887 } else { | 887 } else { | 
| 888 // Use all other arguments as names of files to load and run. | 888 // Use all other arguments as names of files to load and run. | 
| 889 HandleScope handle_scope; | 889 HandleScope handle_scope; | 
| 890 Handle<String> file_name = v8::String::New(str); | 890 Handle<String> file_name = v8::String::New(str); | 
| 891 Handle<String> source = ReadFile(str); | 891 Handle<String> source = ReadFile(str); | 
| 892 (*executed) = true; | |
| 892 if (source.IsEmpty()) { | 893 if (source.IsEmpty()) { | 
| 893 printf("Error reading '%s'\n", str); | 894 printf("Error reading '%s'\n", str); | 
| 894 return 1; | 895 return 1; | 
| 895 } | 896 } | 
| 896 if (!ExecuteString(source, file_name, false, true)) { | 897 if (!ExecuteString(source, file_name, false, true)) { | 
| 897 OnExit(); | 898 OnExit(); | 
| 898 return 1; | 899 return 1; | 
| 899 } | 900 } | 
| 900 } | 901 } | 
| 901 } | 902 } | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 915 return 0; | 916 return 0; | 
| 916 } | 917 } | 
| 917 | 918 | 
| 918 | 919 | 
| 919 int Shell::Main(int argc, char* argv[]) { | 920 int Shell::Main(int argc, char* argv[]) { | 
| 920 // Figure out if we're requested to stress the optimization | 921 // Figure out if we're requested to stress the optimization | 
| 921 // infrastructure by running tests multiple times and forcing | 922 // infrastructure by running tests multiple times and forcing | 
| 922 // optimization in the last run. | 923 // optimization in the last run. | 
| 923 bool FLAG_stress_opt = false; | 924 bool FLAG_stress_opt = false; | 
| 924 bool FLAG_stress_deopt = false; | 925 bool FLAG_stress_deopt = false; | 
| 925 bool run_shell = (argc == 1); | 926 bool FLAG_interactive_shell = false; | 
| 927 bool FLAG_test_shell = false; | |
| 928 bool FLAG_executed = false; | |
| 
Søren Thygesen Gjesse
2011/06/24 11:36:09
FLAG_executed -> executed or script_executed. It i
 | |
| 926 | 929 | 
| 927 for (int i = 0; i < argc; i++) { | 930 for (int i = 0; i < argc; i++) { | 
| 928 if (strcmp(argv[i], "--stress-opt") == 0) { | 931 if (strcmp(argv[i], "--stress-opt") == 0) { | 
| 929 FLAG_stress_opt = true; | 932 FLAG_stress_opt = true; | 
| 930 argv[i] = NULL; | 933 argv[i] = NULL; | 
| 931 } else if (strcmp(argv[i], "--stress-deopt") == 0) { | 934 } else if (strcmp(argv[i], "--stress-deopt") == 0) { | 
| 932 FLAG_stress_deopt = true; | 935 FLAG_stress_deopt = true; | 
| 933 argv[i] = NULL; | 936 argv[i] = NULL; | 
| 934 } else if (strcmp(argv[i], "--noalways-opt") == 0) { | 937 } else if (strcmp(argv[i], "--noalways-opt") == 0) { | 
| 935 // No support for stressing if we can't use --always-opt. | 938 // No support for stressing if we can't use --always-opt. | 
| 936 FLAG_stress_opt = false; | 939 FLAG_stress_opt = false; | 
| 937 FLAG_stress_deopt = false; | 940 FLAG_stress_deopt = false; | 
| 938 } else if (strcmp(argv[i], "--shell") == 0) { | 941 } else if (strcmp(argv[i], "--shell") == 0) { | 
| 939 run_shell = true; | 942 FLAG_interactive_shell = true; | 
| 943 argv[i] = NULL; | |
| 944 } else if (strcmp(argv[i], "--test") == 0) { | |
| 945 FLAG_test_shell = true; | |
| 940 argv[i] = NULL; | 946 argv[i] = NULL; | 
| 941 } | 947 } | 
| 942 } | 948 } | 
| 943 | 949 | 
| 944 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 950 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 
| 945 | 951 | 
| 946 Initialize(); | 952 Initialize(FLAG_test_shell); | 
| 947 | 953 | 
| 948 int result = 0; | 954 int result = 0; | 
| 949 if (FLAG_stress_opt || FLAG_stress_deopt) { | 955 if (FLAG_stress_opt || FLAG_stress_deopt) { | 
| 950 v8::Testing::SetStressRunType( | 956 v8::Testing::SetStressRunType( | 
| 951 FLAG_stress_opt ? v8::Testing::kStressTypeOpt | 957 FLAG_stress_opt ? v8::Testing::kStressTypeOpt | 
| 952 : v8::Testing::kStressTypeDeopt); | 958 : v8::Testing::kStressTypeDeopt); | 
| 953 int stress_runs = v8::Testing::GetStressRuns(); | 959 int stress_runs = v8::Testing::GetStressRuns(); | 
| 954 for (int i = 0; i < stress_runs && result == 0; i++) { | 960 for (int i = 0; i < stress_runs && result == 0; i++) { | 
| 955 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | 961 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | 
| 956 v8::Testing::PrepareStressRun(i); | 962 v8::Testing::PrepareStressRun(i); | 
| 957 result = RunMain(argc, argv); | 963 result = RunMain(argc, argv, &FLAG_executed); | 
| 958 } | 964 } | 
| 959 printf("======== Full Deoptimization =======\n"); | 965 printf("======== Full Deoptimization =======\n"); | 
| 960 v8::Testing::DeoptimizeAll(); | 966 v8::Testing::DeoptimizeAll(); | 
| 961 } else { | 967 } else { | 
| 962 result = RunMain(argc, argv); | 968 result = RunMain(argc, argv, &FLAG_executed); | 
| 963 } | 969 } | 
| 964 | 970 | 
| 965 #ifdef ENABLE_DEBUGGER_SUPPORT | 971 #ifdef ENABLE_DEBUGGER_SUPPORT | 
| 966 if (i::FLAG_remote_debugger) { | 972 if (i::FLAG_remote_debugger) { | 
| 973 InstallUtilityScript(); | |
| 967 RunRemoteDebugger(i::FLAG_debugger_port); | 974 RunRemoteDebugger(i::FLAG_debugger_port); | 
| 968 return 0; | 975 return 0; | 
| 969 } | 976 } | 
| 970 #endif | 977 #endif | 
| 971 | 978 | 
| 972 if (run_shell) { | 979 // Run interactive shell if explicitly requested or if no script has been | 
| 980 // executed, but never on --test | |
| 981 if ((FLAG_interactive_shell || !FLAG_executed) && !FLAG_test_shell) { | |
| 973 InstallUtilityScript(); | 982 InstallUtilityScript(); | 
| 974 RunShell(); | 983 RunShell(); | 
| 975 } | 984 } | 
| 976 | 985 | 
| 977 v8::V8::Dispose(); | 986 v8::V8::Dispose(); | 
| 978 | 987 | 
| 979 return result; | 988 return result; | 
| 980 } | 989 } | 
| 981 | 990 | 
| 982 } // namespace v8 | 991 } // namespace v8 | 
| 983 | 992 | 
| 984 | 993 | 
| 985 #ifndef GOOGLE3 | 994 #ifndef GOOGLE3 | 
| 986 int main(int argc, char* argv[]) { | 995 int main(int argc, char* argv[]) { | 
| 987 return v8::Shell::Main(argc, argv); | 996 return v8::Shell::Main(argc, argv); | 
| 988 } | 997 } | 
| 989 #endif | 998 #endif | 
| OLD | NEW |