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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); | 480 ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); |
481 } | 481 } |
482 } | 482 } |
483 ::printf("+----------------------------------------+-------------+\n"); | 483 ::printf("+----------------------------------------+-------------+\n"); |
484 } | 484 } |
485 if (counters_file_ != NULL) | 485 if (counters_file_ != NULL) |
486 delete counters_file_; | 486 delete counters_file_; |
487 } | 487 } |
488 | 488 |
489 | 489 |
490 static char* ReadChars(const char *name, int* size_out) { | 490 static char* ReadChars(const char* name, int* size_out) { |
491 v8::Unlocker unlocker; // Release the V8 lock while reading files. | 491 v8::Unlocker unlocker; // Release the V8 lock while reading files. |
492 FILE* file = i::OS::FOpen(name, "rb"); | 492 FILE* file = i::OS::FOpen(name, "rb"); |
493 if (file == NULL) return NULL; | 493 if (file == NULL) return NULL; |
494 | 494 |
495 fseek(file, 0, SEEK_END); | 495 fseek(file, 0, SEEK_END); |
496 int size = ftell(file); | 496 int size = ftell(file); |
497 rewind(file); | 497 rewind(file); |
498 | 498 |
499 char* chars = new char[size + 1]; | 499 char* chars = new char[size + 1]; |
500 chars[size] = '\0'; | 500 chars[size] = '\0'; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 for (int i = 1; i < argc; i++) { | 652 for (int i = 1; i < argc; i++) { |
653 char* str = argv[i]; | 653 char* str = argv[i]; |
654 if (strcmp(str, "--shell") == 0) { | 654 if (strcmp(str, "--shell") == 0) { |
655 run_shell = true; | 655 run_shell = true; |
656 } else if (strcmp(str, "--preemption") == 0) { | 656 } else if (strcmp(str, "--preemption") == 0) { |
657 use_preemption = true; | 657 use_preemption = true; |
658 } else if (strcmp(str, "--no-preemption") == 0) { | 658 } else if (strcmp(str, "--no-preemption") == 0) { |
659 use_preemption = false; | 659 use_preemption = false; |
660 } else if (strcmp(str, "--preemption-interval") == 0) { | 660 } else if (strcmp(str, "--preemption-interval") == 0) { |
661 if (i + 1 < argc) { | 661 if (i + 1 < argc) { |
662 char *end = NULL; | 662 char* end = NULL; |
663 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT | 663 preemption_interval = strtol(argv[++i], &end, 10); // NOLINT |
664 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) { | 664 if (preemption_interval <= 0 || *end != '\0' || errno == ERANGE) { |
665 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); | 665 printf("Invalid value for --preemption-interval '%s'\n", argv[i]); |
666 return 1; | 666 return 1; |
667 } | 667 } |
668 } else { | 668 } else { |
669 printf("Missing value for --preemption-interval\n"); | 669 printf("Missing value for --preemption-interval\n"); |
670 return 1; | 670 return 1; |
671 } | 671 } |
672 } else if (strcmp(str, "-f") == 0) { | 672 } else if (strcmp(str, "-f") == 0) { |
673 // Ignore any -f flags for compatibility with other stand-alone | 673 // Ignore any -f flags for compatibility with other stand-alone |
674 // JavaScript engines. | 674 // JavaScript engines. |
675 continue; | 675 continue; |
676 } else if (strncmp(str, "--", 2) == 0) { | 676 } else if (strncmp(str, "--", 2) == 0) { |
677 printf("Warning: unknown flag %s.\nTry --help for options\n", str); | 677 printf("Warning: unknown flag %s.\nTry --help for options\n", str); |
678 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { | 678 } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { |
679 // Execute argument given to -e option directly. | 679 // Execute argument given to -e option directly. |
680 v8::HandleScope handle_scope; | 680 v8::HandleScope handle_scope; |
681 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); | 681 v8::Handle<v8::String> file_name = v8::String::New("unnamed"); |
682 v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); | 682 v8::Handle<v8::String> source = v8::String::New(argv[i + 1]); |
683 if (!ExecuteString(source, file_name, false, true)) { | 683 if (!ExecuteString(source, file_name, false, true)) { |
684 OnExit(); | 684 OnExit(); |
685 return 1; | 685 return 1; |
686 } | 686 } |
687 i++; | 687 i++; |
688 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { | 688 } else if (strcmp(str, "-p") == 0 && i + 1 < argc) { |
689 int size = 0; | 689 int size = 0; |
690 const char *files = ReadChars(argv[++i], &size); | 690 const char* files = ReadChars(argv[++i], &size); |
691 if (files == NULL) return 1; | 691 if (files == NULL) return 1; |
692 ShellThread *thread = | 692 ShellThread* thread = |
693 new ShellThread(threads.length(), | 693 new ShellThread(threads.length(), |
694 i::Vector<const char>(files, size)); | 694 i::Vector<const char>(files, size)); |
695 thread->Start(); | 695 thread->Start(); |
696 threads.Add(thread); | 696 threads.Add(thread); |
697 } else { | 697 } else { |
698 // Use all other arguments as names of files to load and run. | 698 // Use all other arguments as names of files to load and run. |
699 HandleScope handle_scope; | 699 HandleScope handle_scope; |
700 Handle<String> file_name = v8::String::New(str); | 700 Handle<String> file_name = v8::String::New(str); |
701 Handle<String> source = ReadFile(str); | 701 Handle<String> source = ReadFile(str); |
702 if (source.IsEmpty()) { | 702 if (source.IsEmpty()) { |
(...skipping 26 matching lines...) Expand all Loading... |
729 | 729 |
730 // Start the in-process debugger if requested. | 730 // Start the in-process debugger if requested. |
731 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { | 731 if (i::FLAG_debugger && !i::FLAG_debugger_agent) { |
732 v8::Debug::SetDebugEventListener(HandleDebugEvent); | 732 v8::Debug::SetDebugEventListener(HandleDebugEvent); |
733 } | 733 } |
734 #endif | 734 #endif |
735 } | 735 } |
736 if (run_shell) | 736 if (run_shell) |
737 RunShell(); | 737 RunShell(); |
738 for (int i = 0; i < threads.length(); i++) { | 738 for (int i = 0; i < threads.length(); i++) { |
739 i::Thread *thread = threads[i]; | 739 i::Thread* thread = threads[i]; |
740 thread->Join(); | 740 thread->Join(); |
741 delete thread; | 741 delete thread; |
742 } | 742 } |
743 OnExit(); | 743 OnExit(); |
744 return 0; | 744 return 0; |
745 } | 745 } |
746 | 746 |
747 | 747 |
748 } // namespace v8 | 748 } // namespace v8 |
749 | 749 |
750 | 750 |
751 int main(int argc, char* argv[]) { | 751 int main(int argc, char* argv[]) { |
752 return v8::Shell::Main(argc, argv); | 752 return v8::Shell::Main(argc, argv); |
753 } | 753 } |
OLD | NEW |