Chromium Code Reviews| 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 621 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
| 622 arguments_array->set(j, *arg); | 622 arguments_array->set(j, *arg); |
| 623 } | 623 } |
| 624 i::Handle<i::JSArray> arguments_jsarray = | 624 i::Handle<i::JSArray> arguments_jsarray = |
| 625 FACTORY->NewJSArrayWithElements(arguments_array); | 625 FACTORY->NewJSArrayWithElements(arguments_array); |
| 626 global_template->Set(String::New("arguments"), | 626 global_template->Set(String::New("arguments"), |
| 627 Utils::ToLocal(arguments_jsarray)); | 627 Utils::ToLocal(arguments_jsarray)); |
| 628 | 628 |
| 629 #ifdef ENABLE_DEBUGGER_SUPPORT | 629 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 630 // Install the debugger object in the utility scope | 630 // Install the debugger object in the utility scope |
| 631 i::Debug* debug = i::Isolate::Current()->debug(); | 631 i::Debug* debug = i::Isolate::Current()->debug(); |
|
Yang
2011/06/10 12:36:16
still need the current isolate to get the debugger
| |
| 632 debug->Load(); | 632 debug->Load(); |
| 633 i::Handle<i::JSObject> js_debug | 633 i::Handle<i::JSObject> js_debug |
| 634 = i::Handle<i::JSObject>(debug->debug_context()->global()); | 634 = i::Handle<i::JSObject>(debug->debug_context()->global()); |
| 635 utility_context_->Global()->Set(String::New("$debug"), | 635 utility_context_->Global()->Set(String::New("$debug"), |
| 636 Utils::ToLocal(js_debug)); | 636 Utils::ToLocal(js_debug)); |
| 637 #endif | 637 #endif |
| 638 } | 638 } |
| 639 | 639 |
| 640 | 640 |
| 641 void Shell::RenewEvaluationContext() { | 641 void Shell::RenewEvaluationContext() { |
| 642 // Initialize the global objects | 642 // Initialize the global objects |
| 643 HandleScope scope; | 643 HandleScope scope; |
| 644 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 644 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
| 645 | 645 |
| 646 // (Re-)create the evaluation context | 646 // (Re-)create the evaluation context |
| 647 if (!evaluation_context_.IsEmpty()) { | 647 if (!evaluation_context_.IsEmpty()) { |
| 648 evaluation_context_.Dispose(); | 648 evaluation_context_.Dispose(); |
| 649 } | 649 } |
| 650 evaluation_context_ = Context::New(NULL, global_template); | 650 evaluation_context_ = Context::New(NULL, global_template); |
| 651 evaluation_context_->SetSecurityToken(Undefined()); | 651 evaluation_context_->SetSecurityToken(Undefined()); |
| 652 | 652 |
| 653 #ifdef ENABLE_DEBUGGER_SUPPORT | 653 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 654 i::Debug* debug = i::Isolate::Current()->debug(); | 654 i::Debug* debug = i::Isolate::Current()->debug(); |
|
Yang
2011/06/10 12:36:16
ditto
| |
| 655 debug->Load(); | 655 debug->Load(); |
| 656 | 656 |
| 657 // Set the security token of the debug context to allow access. | 657 // Set the security token of the debug context to allow access. |
| 658 debug->debug_context()->set_security_token(HEAP->undefined_value()); | 658 debug->debug_context()->set_security_token(HEAP->undefined_value()); |
| 659 | 659 |
| 660 // Start the debugger agent if requested. | 660 // Start the debugger agent if requested. |
| 661 if (i::FLAG_debugger_agent) { | 661 if (i::FLAG_debugger_agent) { |
| 662 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 662 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
| 663 } | 663 } |
| 664 | 664 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 Handle<String> name = String::New("(d8)"); | 764 Handle<String> name = String::New("(d8)"); |
| 765 ExecuteString(String::New(*input), name, true, true); | 765 ExecuteString(String::New(*input), name, true, true); |
| 766 } | 766 } |
| 767 editor->Close(); | 767 editor->Close(); |
| 768 printf("\n"); | 768 printf("\n"); |
| 769 } | 769 } |
| 770 | 770 |
| 771 | 771 |
| 772 class ShellThread : public i::Thread { | 772 class ShellThread : public i::Thread { |
| 773 public: | 773 public: |
| 774 ShellThread(i::Isolate* isolate, int no, i::Vector<const char> files) | 774 ShellThread(int no, i::Vector<const char> files) |
| 775 : Thread(isolate, "d8:ShellThread"), | 775 : Thread("d8:ShellThread"), |
| 776 no_(no), files_(files) { } | 776 no_(no), files_(files) { } |
| 777 virtual void Run(); | 777 virtual void Run(); |
| 778 private: | 778 private: |
| 779 int no_; | 779 int no_; |
| 780 i::Vector<const char> files_; | 780 i::Vector<const char> files_; |
| 781 }; | 781 }; |
| 782 | 782 |
| 783 | 783 |
| 784 void ShellThread::Run() { | 784 void ShellThread::Run() { |
| 785 // Prepare the context for this thread. | 785 // Prepare the context for this thread. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 v8::Handle<v8::String> source = v8::String::New(argv[++i]); | 872 v8::Handle<v8::String> source = v8::String::New(argv[++i]); |
| 873 if (!ExecuteString(source, file_name, false, true)) { | 873 if (!ExecuteString(source, file_name, false, true)) { |
| 874 OnExit(); | 874 OnExit(); |
| 875 return 1; | 875 return 1; |
| 876 } | 876 } |
| 877 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { | 877 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { |
| 878 int size = 0; | 878 int size = 0; |
| 879 const char* files = ReadChars(argv[++i], &size); | 879 const char* files = ReadChars(argv[++i], &size); |
| 880 if (files == NULL) return 1; | 880 if (files == NULL) return 1; |
| 881 ShellThread* thread = | 881 ShellThread* thread = |
| 882 new ShellThread(i::Isolate::Current(), | 882 new ShellThread(threads.length(), |
| 883 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); |
| 887 } else { | 886 } else { |
| 888 // Use all other arguments as names of files to load and run. | 887 // Use all other arguments as names of files to load and run. |
| 889 HandleScope handle_scope; | 888 HandleScope handle_scope; |
| 890 Handle<String> file_name = v8::String::New(str); | 889 Handle<String> file_name = v8::String::New(str); |
| 891 Handle<String> source = ReadFile(str); | 890 Handle<String> source = ReadFile(str); |
| 892 if (source.IsEmpty()) { | 891 if (source.IsEmpty()) { |
| 893 printf("Error reading '%s'\n", str); | 892 printf("Error reading '%s'\n", str); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 } | 979 } |
| 981 | 980 |
| 982 } // namespace v8 | 981 } // namespace v8 |
| 983 | 982 |
| 984 | 983 |
| 985 #ifndef GOOGLE3 | 984 #ifndef GOOGLE3 |
| 986 int main(int argc, char* argv[]) { | 985 int main(int argc, char* argv[]) { |
| 987 return v8::Shell::Main(argc, argv); | 986 return v8::Shell::Main(argc, argv); |
| 988 } | 987 } |
| 989 #endif | 988 #endif |
| OLD | NEW |