diff options
Diffstat (limited to 'deps/v8/src/d8.cc')
-rw-r--r-- | deps/v8/src/d8.cc | 78 |
1 files changed, 56 insertions, 22 deletions
diff --git a/deps/v8/src/d8.cc b/deps/v8/src/d8.cc index 55f0d4c2ab..9eccc7e4fe 100644 --- a/deps/v8/src/d8.cc +++ b/deps/v8/src/d8.cc @@ -146,11 +146,11 @@ bool Shell::ExecuteString(Handle<String> source, Handle<Value> name, bool print_result, bool report_exceptions) { -#ifndef V8_SHARED +#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) bool FLAG_debugger = i::FLAG_debugger; #else bool FLAG_debugger = false; -#endif // V8_SHARED +#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT HandleScope handle_scope; TryCatch try_catch; options.script_executed = true; @@ -178,7 +178,8 @@ bool Shell::ExecuteString(Handle<String> source, // If all went well and the result wasn't undefined then print // the returned value. v8::String::Utf8Value str(result); - fwrite(*str, sizeof(**str), str.length(), stdout); + size_t count = fwrite(*str, sizeof(**str), str.length(), stdout); + (void) count; // Silence GCC-4.5.x "unused result" warning. printf("\n"); } return true; @@ -594,6 +595,7 @@ void Shell::InstallUtilityScript() { Context::Scope utility_scope(utility_context_); #ifdef ENABLE_DEBUGGER_SUPPORT + if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); // Install the debugger object in the utility scope i::Debug* debug = i::Isolate::Current()->debug(); debug->Load(); @@ -792,22 +794,47 @@ void Shell::Exit(int exit_code) { #ifndef V8_SHARED +struct CounterAndKey { + Counter* counter; + const char* key; +}; + + +int CompareKeys(const void* a, const void* b) { + return strcmp(static_cast<const CounterAndKey*>(a)->key, + static_cast<const CounterAndKey*>(b)->key); +} + + void Shell::OnExit() { if (console != NULL) console->Close(); if (i::FLAG_dump_counters) { - printf("+----------------------------------------+-------------+\n"); - printf("| Name | Value |\n"); - printf("+----------------------------------------+-------------+\n"); + int number_of_counters = 0; for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { - Counter* counter = i.CurrentValue(); + number_of_counters++; + } + CounterAndKey* counters = new CounterAndKey[number_of_counters]; + int j = 0; + for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) { + counters[j].counter = i.CurrentValue(); + counters[j].key = i.CurrentKey(); + } + qsort(counters, number_of_counters, sizeof(counters[0]), CompareKeys); + printf("+--------------------------------------------+-------------+\n"); + printf("| Name | Value |\n"); + printf("+--------------------------------------------+-------------+\n"); + for (j = 0; j < number_of_counters; j++) { + Counter* counter = counters[j].counter; + const char* key = counters[j].key; if (counter->is_histogram()) { - printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); - printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); + printf("| c:%-40s | %11i |\n", key, counter->count()); + printf("| t:%-40s | %11i |\n", key, counter->sample_total()); } else { - printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); + printf("| %-42s | %11i |\n", key, counter->count()); } } - printf("+----------------------------------------+-------------+\n"); + printf("+--------------------------------------------+-------------+\n"); + delete [] counters; } if (counters_file_ != NULL) delete counters_file_; @@ -816,7 +843,7 @@ void Shell::OnExit() { static FILE* FOpen(const char* path, const char* mode) { -#if (defined(_WIN32) || defined(_WIN64)) +#if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) FILE* result; if (fopen_s(&result, path, mode) == 0) { return result; @@ -900,9 +927,6 @@ void Shell::RunShell() { #ifndef V8_SHARED console = LineEditor::Get(); printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); - if (i::FLAG_debugger) { - printf("JavaScript debugger enabled\n"); - } console->Open(); while (true) { i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt); @@ -1253,14 +1277,22 @@ int Shell::RunMain(int argc, char* argv[]) { Locker lock; HandleScope scope; Persistent<Context> context = CreateEvaluationContext(); + if (options.last_run) { + // Keep using the same context in the interactive shell. + evaluation_context_ = context; +#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) + // If the interactive debugger is enabled make sure to activate + // it before running the files passed on the command line. + if (i::FLAG_debugger) { + InstallUtilityScript(); + } +#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT + } { Context::Scope cscope(context); options.isolate_sources[0].Execute(); } - if (options.last_run) { - // Keep using the same context in the interactive shell - evaluation_context_ = context; - } else { + if (!options.last_run) { context.Dispose(); } @@ -1331,9 +1363,11 @@ int Shell::Main(int argc, char* argv[]) { if (( options.interactive_shell || !options.script_executed ) && !options.test_shell ) { -#ifndef V8_SHARED - InstallUtilityScript(); -#endif // V8_SHARED +#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) + if (!i::FLAG_debugger) { + InstallUtilityScript(); + } +#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT RunShell(); } |