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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; |
492 Context::Scope utility_scope(utility_context_); | 492 Context::Scope utility_scope(utility_context_); |
493 | |
494 #ifdef ENABLE_DEBUGGER_SUPPORT | |
495 // Install the debugger object in the utility scope | |
496 i::Debug* debug = i::Isolate::Current()->debug(); | |
497 debug->Load(); | |
498 i::Handle<i::JSObject> js_debug | |
499 = i::Handle<i::JSObject>(debug->debug_context()->global()); | |
500 utility_context_->Global()->Set(String::New("$debug"), | |
501 Utils::ToLocal(js_debug)); | |
502 #endif | |
503 | |
Yang
2011/06/21 02:25:55
This method is called only when using interactive
Søren Thygesen Gjesse
2011/06/21 07:31:06
$debug is a legal identifier, see d8.js where it i
| |
493 // Run the d8 shell utility script in the utility context | 504 // Run the d8 shell utility script in the utility context |
494 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 505 int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |
495 i::Vector<const char> shell_source = | 506 i::Vector<const char> shell_source = |
496 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); | 507 i::NativesCollection<i::D8>::GetRawScriptSource(source_index); |
497 i::Vector<const char> shell_source_name = | 508 i::Vector<const char> shell_source_name = |
498 i::NativesCollection<i::D8>::GetScriptName(source_index); | 509 i::NativesCollection<i::D8>::GetScriptName(source_index); |
499 Handle<String> source = String::New(shell_source.start(), | 510 Handle<String> source = String::New(shell_source.start(), |
500 shell_source.length()); | 511 shell_source.length()); |
501 Handle<String> name = String::New(shell_source_name.start(), | 512 Handle<String> name = String::New(shell_source_name.start(), |
502 shell_source_name.length()); | 513 shell_source_name.length()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 589 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); |
579 #endif | 590 #endif |
580 | 591 |
581 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 592 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
582 AddOSMethods(os_templ); | 593 AddOSMethods(os_templ); |
583 global_template->Set(String::New("os"), os_templ); | 594 global_template->Set(String::New("os"), os_templ); |
584 | 595 |
585 return global_template; | 596 return global_template; |
586 } | 597 } |
587 | 598 |
588 void Shell::Initialize() { | 599 void Shell::Initialize(bool shell) { |
Søren Thygesen Gjesse
2011/06/21 07:31:06
Rename shell to interactive?
| |
589 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 600 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
590 BZip2Decompressor startup_data_decompressor; | 601 BZip2Decompressor startup_data_decompressor; |
591 int bz2_result = startup_data_decompressor.Decompress(); | 602 int bz2_result = startup_data_decompressor.Decompress(); |
592 if (bz2_result != BZ_OK) { | 603 if (bz2_result != BZ_OK) { |
593 fprintf(stderr, "bzip error code: %d\n", bz2_result); | 604 fprintf(stderr, "bzip error code: %d\n", bz2_result); |
594 exit(1); | 605 exit(1); |
595 } | 606 } |
596 #endif | 607 #endif |
597 | 608 |
598 Shell::counter_map_ = new CounterMap(); | 609 Shell::counter_map_ = new CounterMap(); |
599 // Set up counters | 610 // Set up counters |
600 if (i::StrLength(i::FLAG_map_counters) != 0) | 611 if (i::StrLength(i::FLAG_map_counters) != 0) |
601 MapCounters(i::FLAG_map_counters); | 612 MapCounters(i::FLAG_map_counters); |
602 if (i::FLAG_dump_counters) { | 613 if (i::FLAG_dump_counters) { |
603 V8::SetCounterFunction(LookupCounter); | 614 V8::SetCounterFunction(LookupCounter); |
604 V8::SetCreateHistogramFunction(CreateHistogram); | 615 V8::SetCreateHistogramFunction(CreateHistogram); |
605 V8::SetAddHistogramSampleFunction(AddHistogramSample); | 616 V8::SetAddHistogramSampleFunction(AddHistogramSample); |
606 } | 617 } |
607 | 618 if (shell) { |
608 // Initialize the global objects | 619 Locker lock; |
609 HandleScope scope; | 620 HandleScope scope; |
610 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 621 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
611 | 622 utility_context_ = Context::New(NULL, global_template); |
612 utility_context_ = Context::New(NULL, global_template); | 623 utility_context_->SetSecurityToken(Undefined()); |
613 utility_context_->SetSecurityToken(Undefined()); | 624 } |
Yang
2011/06/21 02:25:55
Only initialize utility context if an interactive
| |
614 Context::Scope utility_scope(utility_context_); | |
615 | |
616 #ifdef ENABLE_DEBUGGER_SUPPORT | |
617 // Install the debugger object in the utility scope | |
618 i::Debug* debug = i::Isolate::Current()->debug(); | |
619 debug->Load(); | |
620 i::Handle<i::JSObject> js_debug | |
621 = i::Handle<i::JSObject>(debug->debug_context()->global()); | |
622 utility_context_->Global()->Set(String::New("$debug"), | |
623 Utils::ToLocal(js_debug)); | |
624 #endif | |
625 } | 625 } |
626 | 626 |
627 | 627 |
628 void Shell::RenewEvaluationContext() { | 628 void Shell::RenewEvaluationContext() { |
629 // Initialize the global objects | 629 // Initialize the global objects |
630 HandleScope scope; | 630 HandleScope scope; |
631 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 631 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
632 | 632 |
633 // (Re-)create the evaluation context | 633 // (Re-)create the evaluation context |
634 if (!evaluation_context_.IsEmpty()) { | 634 if (!evaluation_context_.IsEmpty()) { |
635 evaluation_context_.Dispose(); | 635 evaluation_context_.Dispose(); |
636 } | 636 } |
637 evaluation_context_ = Context::New(NULL, global_template); | 637 evaluation_context_ = Context::New(NULL, global_template); |
638 evaluation_context_->SetSecurityToken(Undefined()); | 638 evaluation_context_->SetSecurityToken(Undefined()); |
Søren Thygesen Gjesse
2011/06/21 07:31:06
If we don't set the security token for the evaluat
| |
639 | 639 |
640 Context::Scope utility_scope(utility_context_); | 640 Context::Scope utility_scope(evaluation_context_); |
641 | |
641 i::JSArguments js_args = i::FLAG_js_arguments; | 642 i::JSArguments js_args = i::FLAG_js_arguments; |
642 i::Handle<i::FixedArray> arguments_array = | 643 i::Handle<i::FixedArray> arguments_array = |
643 FACTORY->NewFixedArray(js_args.argc()); | 644 FACTORY->NewFixedArray(js_args.argc()); |
644 for (int j = 0; j < js_args.argc(); j++) { | 645 for (int j = 0; j < js_args.argc(); j++) { |
645 i::Handle<i::String> arg = | 646 i::Handle<i::String> arg = |
646 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 647 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
647 arguments_array->set(j, *arg); | 648 arguments_array->set(j, *arg); |
648 } | 649 } |
649 i::Handle<i::JSArray> arguments_jsarray = | 650 i::Handle<i::JSArray> arguments_jsarray = |
650 FACTORY->NewJSArrayWithElements(arguments_array); | 651 FACTORY->NewJSArrayWithElements(arguments_array); |
651 evaluation_context_->Global()->Set(String::New("arguments"), | 652 evaluation_context_->Global()->Set(String::New("arguments"), |
652 Utils::ToLocal(arguments_jsarray)); | 653 Utils::ToLocal(arguments_jsarray)); |
653 | 654 |
654 #ifdef ENABLE_DEBUGGER_SUPPORT | 655 #ifdef ENABLE_DEBUGGER_SUPPORT |
655 i::Debug* debug = i::Isolate::Current()->debug(); | 656 if (i::FLAG_expose_debug_as != NULL) { |
Yang
2011/06/21 02:25:55
If the debug object is not exposed, there is no po
| |
656 debug->Load(); | 657 i::Debug* debug = i::Isolate::Current()->debug(); |
657 | 658 debug->Load(); |
Søren Thygesen Gjesse
2011/06/21 07:31:06
If --expose-debug-as is specified the debugger is
| |
658 // Set the security token of the debug context to allow access. | 659 // Set the security token of the debug context to allow access. |
659 debug->debug_context()->set_security_token(HEAP->undefined_value()); | 660 debug->debug_context()->set_security_token(HEAP->undefined_value()); |
661 } | |
660 | 662 |
661 // Start the debugger agent if requested. | 663 // Start the debugger agent if requested. |
662 if (i::FLAG_debugger_agent) { | 664 if (i::FLAG_debugger_agent) { |
663 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 665 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
664 } | 666 } |
665 | 667 |
666 // Start the in-process debugger if requested. | 668 // Start the in-process debugger if requested. |
667 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 669 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
668 v8::Debug::SetDebugEventListener(HandleDebugEvent); | 670 v8::Debug::SetDebugEventListener(HandleDebugEvent); |
669 } | 671 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
936 FLAG_stress_opt = false; | 938 FLAG_stress_opt = false; |
937 FLAG_stress_deopt = false; | 939 FLAG_stress_deopt = false; |
938 } else if (strcmp(argv[i], "--shell") == 0) { | 940 } else if (strcmp(argv[i], "--shell") == 0) { |
939 run_shell = true; | 941 run_shell = true; |
940 argv[i] = NULL; | 942 argv[i] = NULL; |
941 } | 943 } |
942 } | 944 } |
943 | 945 |
944 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 946 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
945 | 947 |
946 Initialize(); | 948 Initialize(run_shell); |
Søren Thygesen Gjesse
2011/06/21 07:31:06
I think it will be better to have a flag for runni
| |
947 | 949 |
948 int result = 0; | 950 int result = 0; |
949 if (FLAG_stress_opt || FLAG_stress_deopt) { | 951 if (FLAG_stress_opt || FLAG_stress_deopt) { |
950 v8::Testing::SetStressRunType( | 952 v8::Testing::SetStressRunType( |
951 FLAG_stress_opt ? v8::Testing::kStressTypeOpt | 953 FLAG_stress_opt ? v8::Testing::kStressTypeOpt |
952 : v8::Testing::kStressTypeDeopt); | 954 : v8::Testing::kStressTypeDeopt); |
953 int stress_runs = v8::Testing::GetStressRuns(); | 955 int stress_runs = v8::Testing::GetStressRuns(); |
954 for (int i = 0; i < stress_runs && result == 0; i++) { | 956 for (int i = 0; i < stress_runs && result == 0; i++) { |
955 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | 957 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); |
956 v8::Testing::PrepareStressRun(i); | 958 v8::Testing::PrepareStressRun(i); |
(...skipping 23 matching lines...) Expand all Loading... | |
980 } | 982 } |
981 | 983 |
982 } // namespace v8 | 984 } // namespace v8 |
983 | 985 |
984 | 986 |
985 #ifndef GOOGLE3 | 987 #ifndef GOOGLE3 |
986 int main(int argc, char* argv[]) { | 988 int main(int argc, char* argv[]) { |
987 return v8::Shell::Main(argc, argv); | 989 return v8::Shell::Main(argc, argv); |
988 } | 990 } |
989 #endif | 991 #endif |
OLD | NEW |