Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index 56a43ad2411e375f529beca5a62dd6c2df5469ac..970e937b6d31997ec40bf3abe9eca2471821a679 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -490,6 +490,17 @@ void Shell::InstallUtilityScript() { |
| Locker lock; |
| HandleScope scope; |
| 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)); |
| +#endif |
| + |
|
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
|
| // 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 = |
| @@ -585,7 +596,7 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
| return global_template; |
| } |
| -void Shell::Initialize() { |
| +void Shell::Initialize(bool shell) { |
|
Søren Thygesen Gjesse
2011/06/21 07:31:06
Rename shell to interactive?
|
| #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| BZip2Decompressor startup_data_decompressor; |
| int bz2_result = startup_data_decompressor.Decompress(); |
| @@ -604,24 +615,13 @@ void Shell::Initialize() { |
| V8::SetCreateHistogramFunction(CreateHistogram); |
| V8::SetAddHistogramSampleFunction(AddHistogramSample); |
| } |
| - |
| - // Initialize the global objects |
| - 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)); |
| -#endif |
| + if (shell) { |
| + Locker lock; |
| + HandleScope scope; |
| + Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| + utility_context_ = Context::New(NULL, global_template); |
| + utility_context_->SetSecurityToken(Undefined()); |
| + } |
|
Yang
2011/06/21 02:25:55
Only initialize utility context if an interactive
|
| } |
| @@ -637,7 +637,8 @@ void Shell::RenewEvaluationContext() { |
| evaluation_context_ = Context::New(NULL, global_template); |
| 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
|
| - Context::Scope utility_scope(utility_context_); |
| + Context::Scope utility_scope(evaluation_context_); |
| + |
| i::JSArguments js_args = i::FLAG_js_arguments; |
| i::Handle<i::FixedArray> arguments_array = |
| FACTORY->NewFixedArray(js_args.argc()); |
| @@ -652,11 +653,12 @@ void Shell::RenewEvaluationContext() { |
| 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()); |
| + 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
|
| + i::Debug* debug = i::Isolate::Current()->debug(); |
| + debug->Load(); |
|
Søren Thygesen Gjesse
2011/06/21 07:31:06
If --expose-debug-as is specified the debugger is
|
| + // 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) { |
| @@ -943,7 +945,7 @@ int Shell::Main(int argc, char* argv[]) { |
| v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| - Initialize(); |
| + 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
|
| int result = 0; |
| if (FLAG_stress_opt || FLAG_stress_deopt) { |