diff options
Diffstat (limited to 'deps/v8/src/d8.cc')
-rw-r--r-- | deps/v8/src/d8.cc | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/deps/v8/src/d8.cc b/deps/v8/src/d8.cc index 97828a4ac4..bfb9944027 100644 --- a/deps/v8/src/d8.cc +++ b/deps/v8/src/d8.cc @@ -66,11 +66,7 @@ namespace v8 { - -#ifndef V8_SHARED LineEditor *LineEditor::first_ = NULL; -const char* Shell::kHistoryFileName = ".d8_history"; -const int Shell::kMaxHistoryEntries = 1000; LineEditor::LineEditor(Type type, const char* name) @@ -96,31 +92,29 @@ LineEditor* LineEditor::Get() { class DumbLineEditor: public LineEditor { public: DumbLineEditor() : LineEditor(LineEditor::DUMB, "dumb") { } - virtual i::SmartArrayPointer<char> Prompt(const char* prompt); + virtual Handle<String> Prompt(const char* prompt); }; static DumbLineEditor dumb_line_editor; -i::SmartArrayPointer<char> DumbLineEditor::Prompt(const char* prompt) { - static const int kBufferSize = 256; - char buffer[kBufferSize]; +Handle<String> DumbLineEditor::Prompt(const char* prompt) { printf("%s", prompt); - char* str = fgets(buffer, kBufferSize, stdin); - return i::SmartArrayPointer<char>(str ? i::StrDup(str) : str); + return Shell::ReadFromStdin(); } +#ifndef V8_SHARED CounterMap* Shell::counter_map_; i::OS::MemoryMappedFile* Shell::counters_file_ = NULL; CounterCollection Shell::local_counters_; CounterCollection* Shell::counters_ = &local_counters_; i::Mutex* Shell::context_mutex_(i::OS::CreateMutex()); Persistent<Context> Shell::utility_context_; -LineEditor* Shell::console = NULL; #endif // V8_SHARED +LineEditor* Shell::console = NULL; Persistent<Context> Shell::evaluation_context_; ShellOptions Shell::options; const char* Shell::kPrompt = "d8> "; @@ -238,7 +232,7 @@ Handle<Value> Shell::Read(const Arguments& args) { } -Handle<Value> Shell::ReadLine(const Arguments& args) { +Handle<String> Shell::ReadFromStdin() { static const int kBufferSize = 256; char buffer[kBufferSize]; Handle<String> accumulator = String::New(""); @@ -247,7 +241,12 @@ Handle<Value> Shell::ReadLine(const Arguments& args) { // Continue reading if the line ends with an escape '\\' or the line has // not been fully read into the buffer yet (does not end with '\n'). // If fgets gets an error, just give up. - if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); + char* input = NULL; + { // Release lock for blocking input. + Unlocker unlock(Isolate::GetCurrent()); + input = fgets(buffer, kBufferSize, stdin); + } + if (input == NULL) return Handle<String>(); length = static_cast<int>(strlen(buffer)); if (length == 0) { return accumulator; @@ -532,6 +531,10 @@ Handle<Value> Shell::Version(const Arguments& args) { void Shell::ReportException(v8::TryCatch* try_catch) { HandleScope handle_scope; +#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) + bool enter_context = !Context::InContext(); + if (enter_context) utility_context_->Enter(); +#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT v8::String::Utf8Value exception(try_catch->Exception()); const char* exception_string = ToCString(exception); Handle<Message> message = try_catch->Message(); @@ -566,6 +569,9 @@ void Shell::ReportException(v8::TryCatch* try_catch) { } } printf("\n"); +#if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) + if (enter_context) utility_context_->Exit(); +#endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT } @@ -603,6 +609,12 @@ Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); return val; } + + +void Shell::DispatchDebugMessages() { + v8::Context::Scope scope(Shell::evaluation_context_); + v8::Debug::ProcessDebugMessages(); +} #endif // ENABLE_DEBUGGER_SUPPORT #endif // V8_SHARED @@ -872,6 +884,7 @@ void Shell::Initialize() { // Start the debugger agent if requested. if (i::FLAG_debugger_agent) { v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); + v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); } #endif // ENABLE_DEBUGGER_SUPPORT #endif // V8_SHARED @@ -1047,28 +1060,15 @@ void Shell::RunShell() { Context::Scope context_scope(evaluation_context_); HandleScope outer_scope; Handle<String> name = String::New("(d8)"); -#ifndef V8_SHARED console = LineEditor::Get(); printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); console->Open(); while (true) { - i::SmartArrayPointer<char> input = console->Prompt(Shell::kPrompt); - if (input.is_empty()) break; - console->AddHistory(*input); HandleScope inner_scope; - ExecuteString(String::New(*input), name, true, true); + Handle<String> input = console->Prompt(Shell::kPrompt); + if (input.IsEmpty()) break; + ExecuteString(input, name, true, true); } -#else - printf("V8 version %s [D8 light using shared library]\n", V8::GetVersion()); - static const int kBufferSize = 256; - while (true) { - char buffer[kBufferSize]; - printf("%s", Shell::kPrompt); - if (fgets(buffer, kBufferSize, stdin) == NULL) break; - HandleScope inner_scope; - ExecuteString(String::New(buffer), name, true, true); - } -#endif // V8_SHARED printf("\n"); } |