| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Print errors that happened during execution. | 169 // Print errors that happened during execution. |
| 170 if (report_exceptions && !FLAG_debugger) | 170 if (report_exceptions && !FLAG_debugger) |
| 171 ReportException(&try_catch); | 171 ReportException(&try_catch); |
| 172 return false; | 172 return false; |
| 173 } else { | 173 } else { |
| 174 ASSERT(!try_catch.HasCaught()); | 174 ASSERT(!try_catch.HasCaught()); |
| 175 if (print_result && !result->IsUndefined()) { | 175 if (print_result && !result->IsUndefined()) { |
| 176 // If all went well and the result wasn't undefined then print | 176 // If all went well and the result wasn't undefined then print |
| 177 // the returned value. | 177 // the returned value. |
| 178 v8::String::Utf8Value str(result); | 178 v8::String::Utf8Value str(result); |
| 179 const char* cstr = ToCString(str); | 179 fwrite(*str, sizeof(**str), str.length(), stdout); |
| 180 printf("%s\n", cstr); | 180 printf("\n"); |
| 181 } | 181 } |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 | 187 |
| 188 Handle<Value> Shell::Print(const Arguments& args) { | 188 Handle<Value> Shell::Print(const Arguments& args) { |
| 189 Handle<Value> val = Write(args); | 189 Handle<Value> val = Write(args); |
| 190 printf("\n"); | 190 printf("\n"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 203 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); | 203 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); |
| 204 if (n != str.length()) { | 204 if (n != str.length()) { |
| 205 printf("Error in fwrite\n"); | 205 printf("Error in fwrite\n"); |
| 206 exit(1); | 206 exit(1); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 return Undefined(); | 209 return Undefined(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 | 212 |
| 213 Handle<Value> Shell::EnableProfiler(const Arguments& args) { |
| 214 V8::ResumeProfiler(); |
| 215 return Undefined(); |
| 216 } |
| 217 |
| 218 |
| 219 Handle<Value> Shell::DisableProfiler(const Arguments& args) { |
| 220 V8::PauseProfiler(); |
| 221 return Undefined(); |
| 222 } |
| 223 |
| 224 |
| 213 Handle<Value> Shell::Read(const Arguments& args) { | 225 Handle<Value> Shell::Read(const Arguments& args) { |
| 214 String::Utf8Value file(args[0]); | 226 String::Utf8Value file(args[0]); |
| 215 if (*file == NULL) { | 227 if (*file == NULL) { |
| 216 return ThrowException(String::New("Error loading file")); | 228 return ThrowException(String::New("Error loading file")); |
| 217 } | 229 } |
| 218 Handle<String> source = ReadFile(*file); | 230 Handle<String> source = ReadFile(*file); |
| 219 if (source.IsEmpty()) { | 231 if (source.IsEmpty()) { |
| 220 return ThrowException(String::New("Error loading file")); | 232 return ThrowException(String::New("Error loading file")); |
| 221 } | 233 } |
| 222 return source; | 234 return source; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { | 661 Handle<ObjectTemplate> Shell::CreateGlobalTemplate() { |
| 650 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); | 662 Handle<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 651 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); | 663 global_template->Set(String::New("print"), FunctionTemplate::New(Print)); |
| 652 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); | 664 global_template->Set(String::New("write"), FunctionTemplate::New(Write)); |
| 653 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); | 665 global_template->Set(String::New("read"), FunctionTemplate::New(Read)); |
| 654 global_template->Set(String::New("readline"), | 666 global_template->Set(String::New("readline"), |
| 655 FunctionTemplate::New(ReadLine)); | 667 FunctionTemplate::New(ReadLine)); |
| 656 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 668 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
| 657 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 669 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
| 658 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 670 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
| 671 global_template->Set(String::New("enableProfiler"), |
| 672 FunctionTemplate::New(EnableProfiler)); |
| 673 global_template->Set(String::New("disableProfiler"), |
| 674 FunctionTemplate::New(DisableProfiler)); |
| 659 | 675 |
| 660 // Bind the handlers for external arrays. | 676 // Bind the handlers for external arrays. |
| 661 global_template->Set(String::New("Int8Array"), | 677 global_template->Set(String::New("Int8Array"), |
| 662 FunctionTemplate::New(Int8Array)); | 678 FunctionTemplate::New(Int8Array)); |
| 663 global_template->Set(String::New("Uint8Array"), | 679 global_template->Set(String::New("Uint8Array"), |
| 664 FunctionTemplate::New(Uint8Array)); | 680 FunctionTemplate::New(Uint8Array)); |
| 665 global_template->Set(String::New("Int16Array"), | 681 global_template->Set(String::New("Int16Array"), |
| 666 FunctionTemplate::New(Int16Array)); | 682 FunctionTemplate::New(Int16Array)); |
| 667 global_template->Set(String::New("Uint16Array"), | 683 global_template->Set(String::New("Uint16Array"), |
| 668 FunctionTemplate::New(Uint16Array)); | 684 FunctionTemplate::New(Uint16Array)); |
| 669 global_template->Set(String::New("Int32Array"), | 685 global_template->Set(String::New("Int32Array"), |
| 670 FunctionTemplate::New(Int32Array)); | 686 FunctionTemplate::New(Int32Array)); |
| 671 global_template->Set(String::New("Uint32Array"), | 687 global_template->Set(String::New("Uint32Array"), |
| 672 FunctionTemplate::New(Uint32Array)); | 688 FunctionTemplate::New(Uint32Array)); |
| 673 global_template->Set(String::New("Float32Array"), | 689 global_template->Set(String::New("Float32Array"), |
| 674 FunctionTemplate::New(Float32Array)); | 690 FunctionTemplate::New(Float32Array)); |
| 675 global_template->Set(String::New("Float64Array"), | 691 global_template->Set(String::New("Float64Array"), |
| 676 FunctionTemplate::New(Float64Array)); | 692 FunctionTemplate::New(Float64Array)); |
| 677 global_template->Set(String::New("PixelArray"), | 693 global_template->Set(String::New("PixelArray"), |
| 678 FunctionTemplate::New(PixelArray)); | 694 FunctionTemplate::New(PixelArray)); |
| 679 | 695 |
| 680 #ifdef LIVE_OBJECT_LIST | 696 #ifdef LIVE_OBJECT_LIST |
| 681 global_template->Set(String::New("lol_is_enabled"), Boolean::New(true)); | 697 global_template->Set(String::New("lol_is_enabled"), True()); |
| 682 #else | 698 #else |
| 683 global_template->Set(String::New("lol_is_enabled"), Boolean::New(false)); | 699 global_template->Set(String::New("lol_is_enabled"), False()); |
| 684 #endif | 700 #endif |
| 685 | 701 |
| 686 #ifndef V8_SHARED | 702 #if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64) |
| 687 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); | 703 Handle<ObjectTemplate> os_templ = ObjectTemplate::New(); |
| 688 AddOSMethods(os_templ); | 704 AddOSMethods(os_templ); |
| 689 global_template->Set(String::New("os"), os_templ); | 705 global_template->Set(String::New("os"), os_templ); |
| 690 #endif // V8_SHARED | 706 #endif // V8_SHARED |
| 691 | 707 |
| 692 return global_template; | 708 return global_template; |
| 693 } | 709 } |
| 694 | 710 |
| 695 | 711 |
| 696 void Shell::Initialize() { | 712 void Shell::Initialize() { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 if (chars == NULL) return Handle<String>(); | 873 if (chars == NULL) return Handle<String>(); |
| 858 Handle<String> result = String::New(chars); | 874 Handle<String> result = String::New(chars); |
| 859 delete[] chars; | 875 delete[] chars; |
| 860 return result; | 876 return result; |
| 861 } | 877 } |
| 862 | 878 |
| 863 | 879 |
| 864 void Shell::RunShell() { | 880 void Shell::RunShell() { |
| 865 Locker locker; | 881 Locker locker; |
| 866 Context::Scope context_scope(evaluation_context_); | 882 Context::Scope context_scope(evaluation_context_); |
| 867 HandleScope handle_scope; | 883 HandleScope outer_scope; |
| 868 Handle<String> name = String::New("(d8)"); | 884 Handle<String> name = String::New("(d8)"); |
| 869 #ifndef V8_SHARED | 885 #ifndef V8_SHARED |
| 870 LineEditor* editor = LineEditor::Get(); | 886 LineEditor* editor = LineEditor::Get(); |
| 871 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); | 887 printf("V8 version %s [console: %s]\n", V8::GetVersion(), editor->name()); |
| 872 if (i::FLAG_debugger) { | 888 if (i::FLAG_debugger) { |
| 873 printf("JavaScript debugger enabled\n"); | 889 printf("JavaScript debugger enabled\n"); |
| 874 } | 890 } |
| 875 editor->Open(); | 891 editor->Open(); |
| 876 while (true) { | 892 while (true) { |
| 877 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); | 893 i::SmartPointer<char> input = editor->Prompt(Shell::kPrompt); |
| 878 if (input.is_empty()) break; | 894 if (input.is_empty()) break; |
| 879 editor->AddHistory(*input); | 895 editor->AddHistory(*input); |
| 896 HandleScope inner_scope; |
| 880 ExecuteString(String::New(*input), name, true, true); | 897 ExecuteString(String::New(*input), name, true, true); |
| 881 } | 898 } |
| 882 editor->Close(); | 899 editor->Close(); |
| 883 #else | 900 #else |
| 884 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); | 901 printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); |
| 885 static const int kBufferSize = 256; | 902 static const int kBufferSize = 256; |
| 886 while (true) { | 903 while (true) { |
| 887 char buffer[kBufferSize]; | 904 char buffer[kBufferSize]; |
| 888 printf("%s", Shell::kPrompt); | 905 printf("%s", Shell::kPrompt); |
| 889 if (fgets(buffer, kBufferSize, stdin) == NULL) break; | 906 if (fgets(buffer, kBufferSize, stdin) == NULL) break; |
| 907 HandleScope inner_scope; |
| 890 ExecuteString(String::New(buffer), name, true, true); | 908 ExecuteString(String::New(buffer), name, true, true); |
| 891 } | 909 } |
| 892 #endif // V8_SHARED | 910 #endif // V8_SHARED |
| 893 printf("\n"); | 911 printf("\n"); |
| 894 } | 912 } |
| 895 | 913 |
| 896 | 914 |
| 897 #ifndef V8_SHARED | 915 #ifndef V8_SHARED |
| 898 class ShellThread : public i::Thread { | 916 class ShellThread : public i::Thread { |
| 899 public: | 917 public: |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 } | 1314 } |
| 1297 | 1315 |
| 1298 } // namespace v8 | 1316 } // namespace v8 |
| 1299 | 1317 |
| 1300 | 1318 |
| 1301 #ifndef GOOGLE3 | 1319 #ifndef GOOGLE3 |
| 1302 int main(int argc, char* argv[]) { | 1320 int main(int argc, char* argv[]) { |
| 1303 return v8::Shell::Main(argc, argv); | 1321 return v8::Shell::Main(argc, argv); |
| 1304 } | 1322 } |
| 1305 #endif | 1323 #endif |
| OLD | NEW |