Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index 56a43ad2411e375f529beca5a62dd6c2df5469ac..5a778f6e1b0b5569bab3e9f57fad9da0a24668eb 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -489,7 +489,21 @@ void Shell::AddHistogramSample(void* histogram, int sample) { |
| void Shell::InstallUtilityScript() { |
| Locker lock; |
| HandleScope scope; |
| + utility_context_->SetSecurityToken(Undefined()); |
| + evaluation_context_->SetSecurityToken(Undefined()); |
| Context::Scope utility_scope(utility_context_); |
|
Yang
2011/06/22 00:44:08
I just went with your suggestion to not set the se
|
| + |
| +#ifdef ENABLE_DEBUGGER_SUPPORT |
| + // Install the debugger object in the utility scope |
| + i::Debug* debug = i::Isolate::Current()->debug(); |
| + debug->Load(); |
| + i::Handle<i::JSObject> js_debug |
| + = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| + utility_context_->Global()->Set(String::New("$debug"), |
| + Utils::ToLocal(js_debug)); |
| + debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| +#endif |
| + |
| // Run the d8 shell utility script in the utility context |
| int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |
| i::Vector<const char> shell_source = |
| @@ -514,6 +528,7 @@ void Shell::InstallUtilityScript() { |
| script_object->set_type(i::Smi::FromInt(i::Script::TYPE_NATIVE)); |
| } |
| + |
| #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| class BZip2Decompressor : public v8::StartupDataDecompressor { |
| public: |
| @@ -585,7 +600,8 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
| return global_template; |
| } |
| -void Shell::Initialize() { |
| + |
| +void Shell::Initialize(bool test_shell) { |
|
Yang
2011/06/22 00:44:08
Instead of renaming the argument to "interactive",
|
| #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| BZip2Decompressor startup_data_decompressor; |
| int bz2_result = startup_data_decompressor.Decompress(); |
| @@ -605,22 +621,23 @@ void Shell::Initialize() { |
| V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| } |
| - // Initialize the global objects |
| + if (test_shell) return; |
| + |
| + Locker lock; |
| HandleScope scope; |
| Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| - |
| utility_context_ = Context::New(NULL, global_template); |
| - utility_context_->SetSecurityToken(Undefined()); |
| - Context::Scope utility_scope(utility_context_); |
| #ifdef ENABLE_DEBUGGER_SUPPORT |
| - // Install the debugger object in the utility scope |
| - i::Debug* debug = i::Isolate::Current()->debug(); |
| - debug->Load(); |
| - i::Handle<i::JSObject> js_debug |
| - = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| - utility_context_->Global()->Set(String::New("$debug"), |
| - Utils::ToLocal(js_debug)); |
| + // Start the debugger agent if requested. |
| + if (i::FLAG_debugger_agent) { |
| + v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| + } |
| + |
| + // Start the in-process debugger if requested. |
| + if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
| + v8::Debug::SetDebugEventListener(HandleDebugEvent); |
| + } |
| #endif |
| } |
| @@ -635,9 +652,8 @@ void Shell::RenewEvaluationContext() { |
| evaluation_context_.Dispose(); |
| } |
| evaluation_context_ = Context::New(NULL, global_template); |
| - evaluation_context_->SetSecurityToken(Undefined()); |
| + Context::Scope utility_scope(evaluation_context_); |
| - Context::Scope utility_scope(utility_context_); |
| i::JSArguments js_args = i::FLAG_js_arguments; |
| i::Handle<i::FixedArray> arguments_array = |
| FACTORY->NewFixedArray(js_args.argc()); |
| @@ -650,24 +666,6 @@ void Shell::RenewEvaluationContext() { |
| FACTORY->NewJSArrayWithElements(arguments_array); |
| evaluation_context_->Global()->Set(String::New("arguments"), |
| Utils::ToLocal(arguments_jsarray)); |
| - |
| -#ifdef ENABLE_DEBUGGER_SUPPORT |
| - i::Debug* debug = i::Isolate::Current()->debug(); |
| - debug->Load(); |
| - |
| - // Set the security token of the debug context to allow access. |
| - debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| - |
| - // Start the debugger agent if requested. |
| - if (i::FLAG_debugger_agent) { |
| - v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| - } |
| - |
| - // Start the in-process debugger if requested. |
| - if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
| - v8::Debug::SetDebugEventListener(HandleDebugEvent); |
| - } |
| -#endif |
| } |
| @@ -753,6 +751,7 @@ void Shell::RunShell() { |
| if (i::FLAG_debugger) { |
| printf("JavaScript debugger enabled\n"); |
| } |
| + |
| editor->Open(); |
| while (true) { |
| Locker locker; |
| @@ -800,7 +799,6 @@ void ShellThread::Run() { |
| } |
| Persistent<Context> thread_context = Context::New(NULL, global_template); |
| - thread_context->SetSecurityToken(Undefined()); |
| Context::Scope context_scope(thread_context); |
| while ((ptr != NULL) && (*ptr != '\0')) { |
| @@ -922,7 +920,8 @@ int Shell::Main(int argc, char* argv[]) { |
| // optimization in the last run. |
| bool FLAG_stress_opt = false; |
| bool FLAG_stress_deopt = false; |
| - bool run_shell = (argc == 1); |
| + bool FLAG_interactive_shell = false; |
| + bool FLAG_test_shell = false; |
| for (int i = 0; i < argc; i++) { |
| if (strcmp(argv[i], "--stress-opt") == 0) { |
| @@ -936,14 +935,20 @@ int Shell::Main(int argc, char* argv[]) { |
| FLAG_stress_opt = false; |
| FLAG_stress_deopt = false; |
| } else if (strcmp(argv[i], "--shell") == 0) { |
| - run_shell = true; |
| + FLAG_interactive_shell = true; |
| + argv[i] = NULL; |
| + } else if (strcmp(argv[i], "--test") == 0) { |
| + FLAG_test_shell = true; |
| argv[i] = NULL; |
| } |
| } |
| v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| - Initialize(); |
| + FLAG_interactive_shell = !FLAG_test_shell && |
|
Yang
2011/06/22 00:44:08
Basically states: if using shell for test suites,
|
| + (FLAG_interactive_shell || (argc == 1)); |
| + |
| + Initialize(FLAG_test_shell); |
| int result = 0; |
| if (FLAG_stress_opt || FLAG_stress_deopt) { |
| @@ -964,12 +969,13 @@ int Shell::Main(int argc, char* argv[]) { |
| #ifdef ENABLE_DEBUGGER_SUPPORT |
| if (i::FLAG_remote_debugger) { |
| + InstallUtilityScript(); |
|
Yang
2011/06/22 00:44:08
The remote debugger requires stuff from d8.js, the
|
| RunRemoteDebugger(i::FLAG_debugger_port); |
| return 0; |
| } |
| #endif |
| - if (run_shell) { |
| + if (FLAG_interactive_shell) { |
| InstallUtilityScript(); |
| RunShell(); |
| } |