OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 234 |
235 Handle<String> Shell::ReadFromStdin() { | 235 Handle<String> Shell::ReadFromStdin() { |
236 static const int kBufferSize = 256; | 236 static const int kBufferSize = 256; |
237 char buffer[kBufferSize]; | 237 char buffer[kBufferSize]; |
238 Handle<String> accumulator = String::New(""); | 238 Handle<String> accumulator = String::New(""); |
239 int length; | 239 int length; |
240 while (true) { | 240 while (true) { |
241 // Continue reading if the line ends with an escape '\\' or the line has | 241 // Continue reading if the line ends with an escape '\\' or the line has |
242 // not been fully read into the buffer yet (does not end with '\n'). | 242 // not been fully read into the buffer yet (does not end with '\n'). |
243 // If fgets gets an error, just give up. | 243 // If fgets gets an error, just give up. |
244 if (fgets(buffer, kBufferSize, stdin) == NULL) return Handle<String>(); | 244 char* input = NULL; |
245 { // Release lock for blocking input. | |
246 Unlocker unlock(Isolate::GetCurrent()); | |
247 input = fgets(buffer, kBufferSize, stdin); | |
248 } | |
249 if (input == NULL) return Handle<String>(); | |
245 length = static_cast<int>(strlen(buffer)); | 250 length = static_cast<int>(strlen(buffer)); |
246 if (length == 0) { | 251 if (length == 0) { |
247 return accumulator; | 252 return accumulator; |
248 } else if (buffer[length-1] != '\n') { | 253 } else if (buffer[length-1] != '\n') { |
249 accumulator = String::Concat(accumulator, String::New(buffer, length)); | 254 accumulator = String::Concat(accumulator, String::New(buffer, length)); |
250 } else if (length > 1 && buffer[length-2] == '\\') { | 255 } else if (length > 1 && buffer[length-2] == '\\') { |
251 buffer[length-2] = '\n'; | 256 buffer[length-2] = '\n'; |
252 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); | 257 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); |
253 } else { | 258 } else { |
254 return String::Concat(accumulator, String::New(buffer, length-1)); | 259 return String::Concat(accumulator, String::New(buffer, length-1)); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 | 602 |
598 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { | 603 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { |
599 Context::Scope context_scope(utility_context_); | 604 Context::Scope context_scope(utility_context_); |
600 Handle<Object> global = utility_context_->Global(); | 605 Handle<Object> global = utility_context_->Global(); |
601 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); | 606 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); |
602 static const int kArgc = 1; | 607 static const int kArgc = 1; |
603 Handle<Value> argv[kArgc] = { command }; | 608 Handle<Value> argv[kArgc] = { command }; |
604 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 609 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
605 return val; | 610 return val; |
606 } | 611 } |
612 | |
613 | |
614 void Shell::DispatchDebugMessages() { | |
615 printf("message trying to be dispatched\n"); | |
Jakob Kummerow
2012/01/20 11:53:31
intentional?
Yang
2012/01/20 11:59:51
Forgot to remove this debug message. Done.
| |
616 v8::Context::Scope scope(Shell::evaluation_context_); | |
617 v8::Debug::ProcessDebugMessages(); | |
618 } | |
607 #endif // ENABLE_DEBUGGER_SUPPORT | 619 #endif // ENABLE_DEBUGGER_SUPPORT |
608 #endif // V8_SHARED | 620 #endif // V8_SHARED |
609 | 621 |
610 | 622 |
611 #ifndef V8_SHARED | 623 #ifndef V8_SHARED |
612 int32_t* Counter::Bind(const char* name, bool is_histogram) { | 624 int32_t* Counter::Bind(const char* name, bool is_histogram) { |
613 int i; | 625 int i; |
614 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 626 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |
615 name_[i] = static_cast<char>(name[i]); | 627 name_[i] = static_cast<char>(name[i]); |
616 name_[i] = '\0'; | 628 name_[i] = '\0'; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 #ifndef V8_SHARED | 878 #ifndef V8_SHARED |
867 Locker lock; | 879 Locker lock; |
868 HandleScope scope; | 880 HandleScope scope; |
869 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); | 881 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(); |
870 utility_context_ = Context::New(NULL, global_template); | 882 utility_context_ = Context::New(NULL, global_template); |
871 | 883 |
872 #ifdef ENABLE_DEBUGGER_SUPPORT | 884 #ifdef ENABLE_DEBUGGER_SUPPORT |
873 // Start the debugger agent if requested. | 885 // Start the debugger agent if requested. |
874 if (i::FLAG_debugger_agent) { | 886 if (i::FLAG_debugger_agent) { |
875 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); | 887 v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true); |
888 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true); | |
876 } | 889 } |
877 #endif // ENABLE_DEBUGGER_SUPPORT | 890 #endif // ENABLE_DEBUGGER_SUPPORT |
878 #endif // V8_SHARED | 891 #endif // V8_SHARED |
879 } | 892 } |
880 | 893 |
881 | 894 |
882 Persistent<Context> Shell::CreateEvaluationContext() { | 895 Persistent<Context> Shell::CreateEvaluationContext() { |
883 #ifndef V8_SHARED | 896 #ifndef V8_SHARED |
884 // This needs to be a critical section since this is not thread-safe | 897 // This needs to be a critical section since this is not thread-safe |
885 i::ScopedLock lock(context_mutex_); | 898 i::ScopedLock lock(context_mutex_); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1492 } | 1505 } |
1493 | 1506 |
1494 } // namespace v8 | 1507 } // namespace v8 |
1495 | 1508 |
1496 | 1509 |
1497 #ifndef GOOGLE3 | 1510 #ifndef GOOGLE3 |
1498 int main(int argc, char* argv[]) { | 1511 int main(int argc, char* argv[]) { |
1499 return v8::Shell::Main(argc, argv); | 1512 return v8::Shell::Main(argc, argv); |
1500 } | 1513 } |
1501 #endif | 1514 #endif |
OLD | NEW |