Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/debug.cc

Issue 276433004: Clean up Debugger::NotifyMessageHandler. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "api.h" 7 #include "api.h"
8 #include "arguments.h" 8 #include "arguments.h"
9 #include "bootstrapper.h" 9 #include "bootstrapper.h"
10 #include "code-stubs.h" 10 #include "code-stubs.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 isolate_(isolate) { 42 isolate_(isolate) {
43 memset(registers_, 0, sizeof(JSCallerSavedBuffer)); 43 memset(registers_, 0, sizeof(JSCallerSavedBuffer));
44 ThreadInit(); 44 ThreadInit();
45 } 45 }
46 46
47 47
48 Debug::~Debug() { 48 Debug::~Debug() {
49 } 49 }
50 50
51 51
52 static void PrintLn(v8::Local<v8::Value> value) {
53 v8::Local<v8::String> s = value->ToString();
54 ScopedVector<char> data(s->Utf8Length() + 1);
55 if (data.start() == NULL) {
56 V8::FatalProcessOutOfMemory("PrintLn");
57 return;
58 }
59 s->WriteUtf8(data.start());
60 PrintF("%s\n", data.start());
61 }
62
63
64 static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) { 52 static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) {
65 Handle<Context> context = isolate->debug()->debugger_entry()->GetContext(); 53 Handle<Context> context = isolate->debug()->debugger_entry()->GetContext();
66 // Isolate::context() may have been NULL when "script collected" event 54 // Isolate::context() may have been NULL when "script collected" event
67 // occured. 55 // occured.
68 if (context.is_null()) return v8::Local<v8::Context>(); 56 if (context.is_null()) return v8::Local<v8::Context>();
69 Handle<Context> native_context(context->native_context()); 57 Handle<Context> native_context(context->native_context());
70 return v8::Utils::ToLocal(native_context); 58 return v8::Utils::ToLocal(native_context);
71 } 59 }
72 60
73 61
(...skipping 2985 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 3047
3060 // Clear the flag indicating that the debugger should be unloaded. 3048 // Clear the flag indicating that the debugger should be unloaded.
3061 debugger_unload_pending_ = false; 3049 debugger_unload_pending_ = false;
3062 } 3050 }
3063 3051
3064 3052
3065 void Debugger::NotifyMessageHandler(v8::DebugEvent event, 3053 void Debugger::NotifyMessageHandler(v8::DebugEvent event,
3066 Handle<JSObject> exec_state, 3054 Handle<JSObject> exec_state,
3067 Handle<JSObject> event_data, 3055 Handle<JSObject> event_data,
3068 bool auto_continue) { 3056 bool auto_continue) {
3069 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_);
3070 HandleScope scope(isolate_); 3057 HandleScope scope(isolate_);
3071 3058
3072 if (!isolate_->debug()->Load()) return; 3059 if (!isolate_->debug()->Load()) return;
3073 3060
3074 // Process the individual events. 3061 // Process the individual events.
3075 bool sendEventMessage = false; 3062 bool sendEventMessage = false;
3076 switch (event) { 3063 switch (event) {
3077 case v8::Break: 3064 case v8::Break:
3078 case v8::BreakForCommand: 3065 case v8::BreakForCommand:
3079 sendEventMessage = !auto_continue; 3066 sendEventMessage = !auto_continue;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 } 3100 }
3114 3101
3115 // If auto continue don't make the event cause a break, but process messages 3102 // If auto continue don't make the event cause a break, but process messages
3116 // in the queue if any. For script collected events don't even process 3103 // in the queue if any. For script collected events don't even process
3117 // messages in the queue as the execution state might not be what is expected 3104 // messages in the queue as the execution state might not be what is expected
3118 // by the client. 3105 // by the client.
3119 if ((auto_continue && !HasCommands()) || event == v8::ScriptCollected) { 3106 if ((auto_continue && !HasCommands()) || event == v8::ScriptCollected) {
3120 return; 3107 return;
3121 } 3108 }
3122 3109
3123 v8::TryCatch try_catch;
3124
3125 // DebugCommandProcessor goes here. 3110 // DebugCommandProcessor goes here.
3126 v8::Local<v8::Object> cmd_processor;
3127 {
3128 v8::Local<v8::Object> api_exec_state =
3129 v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state));
3130 v8::Local<v8::String> fun_name = v8::String::NewFromUtf8(
3131 isolate, "debugCommandProcessor");
3132 v8::Local<v8::Function> fun =
3133 v8::Local<v8::Function>::Cast(api_exec_state->Get(fun_name));
3134
3135 v8::Handle<v8::Boolean> running = v8::Boolean::New(isolate, auto_continue);
3136 static const int kArgc = 1;
3137 v8::Handle<Value> argv[kArgc] = { running };
3138 cmd_processor = v8::Local<v8::Object>::Cast(
3139 fun->Call(api_exec_state, kArgc, argv));
3140 if (try_catch.HasCaught()) {
3141 PrintLn(try_catch.Exception());
3142 return;
3143 }
3144 }
3145
3146 bool running = auto_continue; 3111 bool running = auto_continue;
3147 3112
3113 Handle<Object> cmd_processor_ctor = Object::GetProperty(
3114 isolate_, exec_state, "debugCommandProcessor").ToHandleChecked();
3115 Handle<Object> ctor_args[] = { isolate_->factory()->ToBoolean(running) };
3116 Handle<Object> cmd_processor = Execution::Call(
3117 isolate_, cmd_processor_ctor, exec_state, 1, ctor_args).ToHandleChecked();
ulan 2014/05/09 08:10:34 Why did you remove v8::TryCatch try_catch here and
Yang 2014/05/09 08:36:14 We don't expect this to fail. If it indeed does, s
3118 Handle<JSFunction> process_debug_request = Handle<JSFunction>::cast(
3119 Object::GetProperty(
3120 isolate_, cmd_processor, "processDebugRequest").ToHandleChecked());
3121 Handle<Object> is_running = Object::GetProperty(
3122 isolate_, cmd_processor, "isRunning").ToHandleChecked();
3123
3148 // Process requests from the debugger. 3124 // Process requests from the debugger.
3149 while (true) { 3125 do {
3150 // Wait for new command in the queue. 3126 // Wait for new command in the queue.
3151 command_received_.Wait(); 3127 command_received_.Wait();
3152 3128
3153 // Get the command from the queue. 3129 // Get the command from the queue.
3154 CommandMessage command = command_queue_.Get(); 3130 CommandMessage command = command_queue_.Get();
3155 isolate_->logger()->DebugTag( 3131 isolate_->logger()->DebugTag(
3156 "Got request from command queue, in interactive loop."); 3132 "Got request from command queue, in interactive loop.");
3157 if (!Debugger::IsDebuggerActive()) { 3133 if (!Debugger::IsDebuggerActive()) {
3158 // Delete command text and user data. 3134 // Delete command text and user data.
3159 command.Dispose(); 3135 command.Dispose();
3160 return; 3136 return;
3161 } 3137 }
3162 3138
3163 // Invoke JavaScript to process the debug request. 3139 Vector<const uc16> command_text(
3164 v8::Local<v8::String> fun_name; 3140 const_cast<const uc16*>(command.text().start()),
3165 v8::Local<v8::Function> fun; 3141 command.text().length());
3166 v8::Local<v8::Value> request; 3142 Handle<String> request_text = isolate_->factory()->NewStringFromTwoByte(
3167 v8::TryCatch try_catch; 3143 command_text).ToHandleChecked();
3168 fun_name = v8::String::NewFromUtf8(isolate, "processDebugRequest"); 3144 Handle<Object> request_args[] = { request_text };
3169 fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); 3145 Handle<Object> exception;
3146 Handle<Object> answer_value;
3147 Handle<String> answer;
3148 MaybeHandle<Object> maybe_result = Execution::TryCall(
3149 process_debug_request, cmd_processor, 1, request_args, &exception);
3170 3150
3171 request = v8::String::NewFromTwoByte(isolate, command.text().start(), 3151 if (maybe_result.ToHandle(&answer_value)) {
3172 v8::String::kNormalString, 3152 if (answer_value->IsUndefined()) {
3173 command.text().length()); 3153 answer = isolate_->factory()->empty_string();
3174 static const int kArgc = 1;
3175 v8::Handle<Value> argv[kArgc] = { request };
3176 v8::Local<v8::Value> response_val = fun->Call(cmd_processor, kArgc, argv);
3177
3178 // Get the response.
3179 v8::Local<v8::String> response;
3180 if (!try_catch.HasCaught()) {
3181 // Get response string.
3182 if (!response_val->IsUndefined()) {
3183 response = v8::Local<v8::String>::Cast(response_val);
3184 } else { 3154 } else {
3185 response = v8::String::NewFromUtf8(isolate, ""); 3155 answer = Handle<String>::cast(answer_value);
3186 } 3156 }
3187 3157
3188 // Log the JSON request/response. 3158 // Log the JSON request/response.
3189 if (FLAG_trace_debug_json) { 3159 if (FLAG_trace_debug_json) {
3190 PrintLn(request); 3160 request_text->PrintLn();
ulan 2014/05/09 08:10:34 Will this compile with release without object-prin
Yang 2014/05/09 08:36:14 You are right. Fixed that.
3191 PrintLn(response); 3161 answer->PrintLn();
3192 } 3162 }
3193 3163
3194 // Get the running state. 3164 Handle<Object> is_running_args[] = { answer };
3195 fun_name = v8::String::NewFromUtf8(isolate, "isRunning"); 3165 maybe_result = Execution::Call(
3196 fun = v8::Local<v8::Function>::Cast(cmd_processor->Get(fun_name)); 3166 isolate_, is_running, cmd_processor, 1, is_running_args);
3197 static const int kArgc = 1; 3167 running = maybe_result.ToHandleChecked()->IsTrue();
3198 v8::Handle<Value> argv[kArgc] = { response };
3199 v8::Local<v8::Value> running_val = fun->Call(cmd_processor, kArgc, argv);
3200 if (!try_catch.HasCaught()) {
3201 running = running_val->ToBoolean()->Value();
3202 }
3203 } else { 3168 } else {
3204 // In case of failure the result text is the exception text. 3169 answer = Handle<String>::cast(
3205 response = try_catch.Exception()->ToString(); 3170 Execution::ToString(isolate_, exception).ToHandleChecked());
3206 } 3171 }
3207 3172
3208 // Return the result. 3173 // Return the result.
3209 MessageImpl message = MessageImpl::NewResponse( 3174 MessageImpl message = MessageImpl::NewResponse(
3210 event, 3175 event, running, exec_state, event_data, answer, command.client_data());
3211 running,
3212 Handle<JSObject>::cast(exec_state),
3213 Handle<JSObject>::cast(event_data),
3214 Handle<String>(Utils::OpenHandle(*response)),
3215 command.client_data());
3216 InvokeMessageHandler(message); 3176 InvokeMessageHandler(message);
3217 command.Dispose(); 3177 command.Dispose();
3218 3178
3219 // Return from debug event processing if either the VM is put into the 3179 // Return from debug event processing if either the VM is put into the
3220 // running state (through a continue command) or auto continue is active 3180 // running state (through a continue command) or auto continue is active
3221 // and there are no more commands queued. 3181 // and there are no more commands queued.
3222 if (running && !HasCommands()) { 3182 } while (!running || HasCommands());
3223 return;
3224 }
3225 }
3226 } 3183 }
3227 3184
3228 3185
3229 void Debugger::SetEventListener(Handle<Object> callback, 3186 void Debugger::SetEventListener(Handle<Object> callback,
3230 Handle<Object> data) { 3187 Handle<Object> data) {
3231 HandleScope scope(isolate_); 3188 HandleScope scope(isolate_);
3232 GlobalHandles* global_handles = isolate_->global_handles(); 3189 GlobalHandles* global_handles = isolate_->global_handles();
3233 3190
3234 // Clear the global handles for the event listener and the event listener data 3191 // Clear the global handles for the event listener and the event listener data
3235 // object. 3192 // object.
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
3828 already_signalled_ = false; 3785 already_signalled_ = false;
3829 } 3786 }
3830 { 3787 {
3831 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); 3788 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_));
3832 isolate_->debugger()->CallMessageDispatchHandler(); 3789 isolate_->debugger()->CallMessageDispatchHandler();
3833 } 3790 }
3834 } 3791 }
3835 } 3792 }
3836 3793
3837 } } // namespace v8::internal 3794 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698