| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  239   Context::Scope context_scope(utility_context_); |  239   Context::Scope context_scope(utility_context_); | 
|  240   Handle<Object> global = utility_context_->Global(); |  240   Handle<Object> global = utility_context_->Global(); | 
|  241   Handle<Value> fun = global->Get(String::New("GetCompletions")); |  241   Handle<Value> fun = global->Get(String::New("GetCompletions")); | 
|  242   static const int kArgc = 3; |  242   static const int kArgc = 3; | 
|  243   Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; |  243   Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; | 
|  244   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |  244   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 
|  245   return handle_scope.Close(Handle<Array>::Cast(val)); |  245   return handle_scope.Close(Handle<Array>::Cast(val)); | 
|  246 } |  246 } | 
|  247  |  247  | 
|  248  |  248  | 
 |  249 #ifdef ENABLE_DEBUGGER_SUPPORT | 
|  249 Handle<Object> Shell::DebugMessageDetails(Handle<String> message) { |  250 Handle<Object> Shell::DebugMessageDetails(Handle<String> message) { | 
|  250   Context::Scope context_scope(utility_context_); |  251   Context::Scope context_scope(utility_context_); | 
|  251   Handle<Object> global = utility_context_->Global(); |  252   Handle<Object> global = utility_context_->Global(); | 
|  252   Handle<Value> fun = global->Get(String::New("DebugMessageDetails")); |  253   Handle<Value> fun = global->Get(String::New("DebugMessageDetails")); | 
|  253   static const int kArgc = 1; |  254   static const int kArgc = 1; | 
|  254   Handle<Value> argv[kArgc] = { message }; |  255   Handle<Value> argv[kArgc] = { message }; | 
|  255   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |  256   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 
|  256   return Handle<Object>::Cast(val); |  257   return Handle<Object>::Cast(val); | 
|  257 } |  258 } | 
|  258  |  259  | 
|  259  |  260  | 
|  260 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { |  261 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { | 
|  261   Context::Scope context_scope(utility_context_); |  262   Context::Scope context_scope(utility_context_); | 
|  262   Handle<Object> global = utility_context_->Global(); |  263   Handle<Object> global = utility_context_->Global(); | 
|  263   Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); |  264   Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); | 
|  264   static const int kArgc = 1; |  265   static const int kArgc = 1; | 
|  265   Handle<Value> argv[kArgc] = { command }; |  266   Handle<Value> argv[kArgc] = { command }; | 
|  266   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |  267   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 
|  267   return val; |  268   return val; | 
|  268 } |  269 } | 
 |  270 #endif | 
|  269  |  271  | 
|  270  |  272  | 
|  271 int32_t* Counter::Bind(const char* name, bool is_histogram) { |  273 int32_t* Counter::Bind(const char* name, bool is_histogram) { | 
|  272   int i; |  274   int i; | 
|  273   for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |  275   for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 
|  274     name_[i] = static_cast<char>(name[i]); |  276     name_[i] = static_cast<char>(name[i]); | 
|  275   name_[i] = '\0'; |  277   name_[i] = '\0'; | 
|  276   is_histogram_ = is_histogram; |  278   is_histogram_ = is_histogram; | 
|  277   return ptr(); |  279   return ptr(); | 
|  278 } |  280 } | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  399   for (int j = 0; j < js_args.argc(); j++) { |  401   for (int j = 0; j < js_args.argc(); j++) { | 
|  400     i::Handle<i::String> arg = |  402     i::Handle<i::String> arg = | 
|  401         i::Factory::NewStringFromUtf8(i::CStrVector(js_args[j])); |  403         i::Factory::NewStringFromUtf8(i::CStrVector(js_args[j])); | 
|  402     arguments_array->set(j, *arg); |  404     arguments_array->set(j, *arg); | 
|  403   } |  405   } | 
|  404   i::Handle<i::JSArray> arguments_jsarray = |  406   i::Handle<i::JSArray> arguments_jsarray = | 
|  405       i::Factory::NewJSArrayWithElements(arguments_array); |  407       i::Factory::NewJSArrayWithElements(arguments_array); | 
|  406   global_template->Set(String::New("arguments"), |  408   global_template->Set(String::New("arguments"), | 
|  407                        Utils::ToLocal(arguments_jsarray)); |  409                        Utils::ToLocal(arguments_jsarray)); | 
|  408  |  410  | 
 |  411 #ifdef ENABLE_DEBUGGER_SUPPORT | 
|  409   // Install the debugger object in the utility scope |  412   // Install the debugger object in the utility scope | 
|  410   i::Debug::Load(); |  413   i::Debug::Load(); | 
|  411   i::JSObject* debug = i::Debug::debug_context()->global(); |  414   i::JSObject* debug = i::Debug::debug_context()->global(); | 
|  412   utility_context_->Global()->Set(String::New("$debug"), |  415   utility_context_->Global()->Set(String::New("$debug"), | 
|  413                                   Utils::ToLocal(&debug)); |  416                                   Utils::ToLocal(&debug)); | 
 |  417 #endif | 
|  414  |  418  | 
|  415   // Run the d8 shell utility script in the utility context |  419   // Run the d8 shell utility script in the utility context | 
|  416   int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); |  420   int source_index = i::NativesCollection<i::D8>::GetIndex("d8"); | 
|  417   i::Vector<const char> shell_source |  421   i::Vector<const char> shell_source | 
|  418       = i::NativesCollection<i::D8>::GetScriptSource(source_index); |  422       = i::NativesCollection<i::D8>::GetScriptSource(source_index); | 
|  419   i::Vector<const char> shell_source_name |  423   i::Vector<const char> shell_source_name | 
|  420       = i::NativesCollection<i::D8>::GetScriptName(source_index); |  424       = i::NativesCollection<i::D8>::GetScriptName(source_index); | 
|  421   Handle<String> source = String::New(shell_source.start(), |  425   Handle<String> source = String::New(shell_source.start(), | 
|  422                                       shell_source.length()); |  426                                       shell_source.length()); | 
|  423   Handle<String> name = String::New(shell_source_name.start(), |  427   Handle<String> name = String::New(shell_source_name.start(), | 
|  424                                     shell_source_name.length()); |  428                                     shell_source_name.length()); | 
|  425   Handle<Script> script = Script::Compile(source, name); |  429   Handle<Script> script = Script::Compile(source, name); | 
|  426   script->Run(); |  430   script->Run(); | 
|  427  |  431  | 
|  428   // Mark the d8 shell script as native to avoid it showing up as normal source |  432   // Mark the d8 shell script as native to avoid it showing up as normal source | 
|  429   // in the debugger. |  433   // in the debugger. | 
|  430   i::Handle<i::JSFunction> script_fun = Utils::OpenHandle(*script); |  434   i::Handle<i::JSFunction> script_fun = Utils::OpenHandle(*script); | 
|  431   i::Handle<i::Script> script_object = |  435   i::Handle<i::Script> script_object = | 
|  432       i::Handle<i::Script>(i::Script::cast(script_fun->shared()->script())); |  436       i::Handle<i::Script>(i::Script::cast(script_fun->shared()->script())); | 
|  433   script_object->set_type(i::Smi::FromInt(i::SCRIPT_TYPE_NATIVE)); |  437   script_object->set_type(i::Smi::FromInt(i::SCRIPT_TYPE_NATIVE)); | 
|  434  |  438  | 
|  435   // Create the evaluation context |  439   // Create the evaluation context | 
|  436   evaluation_context_ = Context::New(NULL, global_template); |  440   evaluation_context_ = Context::New(NULL, global_template); | 
|  437   evaluation_context_->SetSecurityToken(Undefined()); |  441   evaluation_context_->SetSecurityToken(Undefined()); | 
|  438  |  442  | 
 |  443 #ifdef ENABLE_DEBUGGER_SUPPORT | 
|  439   // Set the security token of the debug context to allow access. |  444   // Set the security token of the debug context to allow access. | 
|  440   i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); |  445   i::Debug::debug_context()->set_security_token(i::Heap::undefined_value()); | 
 |  446 #endif | 
|  441 } |  447 } | 
|  442  |  448  | 
|  443  |  449  | 
|  444 void Shell::OnExit() { |  450 void Shell::OnExit() { | 
|  445   if (i::FLAG_dump_counters) { |  451   if (i::FLAG_dump_counters) { | 
|  446     ::printf("+----------------------------------------+-------------+\n"); |  452     ::printf("+----------------------------------------+-------------+\n"); | 
|  447     ::printf("| Name                                   | Value       |\n"); |  453     ::printf("| Name                                   | Value       |\n"); | 
|  448     ::printf("+----------------------------------------+-------------+\n"); |  454     ::printf("+----------------------------------------+-------------+\n"); | 
|  449     for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { |  455     for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { | 
|  450       Counter* counter = i.CurrentValue(); |  456       Counter* counter = i.CurrentValue(); | 
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  683           return 1; |  689           return 1; | 
|  684         } |  690         } | 
|  685       } |  691       } | 
|  686     } |  692     } | 
|  687  |  693  | 
|  688     // Start preemption if threads have been created and preemption is enabled. |  694     // Start preemption if threads have been created and preemption is enabled. | 
|  689     if (threads.length() > 0 && use_preemption) { |  695     if (threads.length() > 0 && use_preemption) { | 
|  690       Locker::StartPreemption(preemption_interval); |  696       Locker::StartPreemption(preemption_interval); | 
|  691     } |  697     } | 
|  692  |  698  | 
 |  699 #ifdef ENABLE_DEBUGGER_SUPPORT | 
|  693     // Run the remote debugger if requested. |  700     // Run the remote debugger if requested. | 
|  694     if (i::FLAG_remote_debugger) { |  701     if (i::FLAG_remote_debugger) { | 
|  695       RunRemoteDebugger(i::FLAG_debugger_port); |  702       RunRemoteDebugger(i::FLAG_debugger_port); | 
|  696       return 0; |  703       return 0; | 
|  697     } |  704     } | 
|  698  |  705  | 
|  699     // Start the debugger agent if requested. |  706     // Start the debugger agent if requested. | 
|  700     if (i::FLAG_debugger_agent) { |  707     if (i::FLAG_debugger_agent) { | 
|  701       v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port); |  708       v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port); | 
|  702     } |  709     } | 
|  703  |  710  | 
|  704     // Start the in-process debugger if requested. |  711     // Start the in-process debugger if requested. | 
|  705     if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |  712     if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 
|  706       v8::Debug::SetDebugEventListener(HandleDebugEvent); |  713       v8::Debug::SetDebugEventListener(HandleDebugEvent); | 
|  707     } |  714     } | 
 |  715 #endif | 
|  708   } |  716   } | 
|  709   if (run_shell) |  717   if (run_shell) | 
|  710     RunShell(); |  718     RunShell(); | 
|  711   for (int i = 0; i < threads.length(); i++) { |  719   for (int i = 0; i < threads.length(); i++) { | 
|  712     i::Thread *thread = threads[i]; |  720     i::Thread *thread = threads[i]; | 
|  713     thread->Join(); |  721     thread->Join(); | 
|  714     delete thread; |  722     delete thread; | 
|  715   } |  723   } | 
|  716   OnExit(); |  724   OnExit(); | 
|  717   return 0; |  725   return 0; | 
|  718 } |  726 } | 
|  719  |  727  | 
|  720  |  728  | 
|  721 }  // namespace v8 |  729 }  // namespace v8 | 
|  722  |  730  | 
|  723  |  731  | 
|  724 int main(int argc, char* argv[]) { |  732 int main(int argc, char* argv[]) { | 
|  725   return v8::Shell::Main(argc, argv); |  733   return v8::Shell::Main(argc, argv); | 
|  726 } |  734 } | 
| OLD | NEW |