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

Side by Side Diff: test/cctest/test-debug.cc

Issue 99122: Changed the debugger message API to receive an object instead of a JSON string (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 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 | « src/debug-agent.cc ('k') | 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 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 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 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3420 */ 3420 */
3421 Barriers message_queue_barriers; 3421 Barriers message_queue_barriers;
3422 3422
3423 // This is the debugger thread, that executes no v8 calls except 3423 // This is the debugger thread, that executes no v8 calls except
3424 // placing JSON debugger commands in the queue. 3424 // placing JSON debugger commands in the queue.
3425 class MessageQueueDebuggerThread : public v8::internal::Thread { 3425 class MessageQueueDebuggerThread : public v8::internal::Thread {
3426 public: 3426 public:
3427 void Run(); 3427 void Run();
3428 }; 3428 };
3429 3429
3430 static void MessageHandler(const uint16_t* message, int length, 3430 static void MessageHandler(const v8::Debug::Message& message) {
3431 v8::Debug::ClientData* client_data) {
3432 static char print_buffer[1000]; 3431 static char print_buffer[1000];
3433 Utf16ToAscii(message, length, print_buffer); 3432 v8::String::Value json(message.GetJSON());
3433 Utf16ToAscii(*json, json.length(), print_buffer);
3434 if (IsBreakEventMessage(print_buffer)) { 3434 if (IsBreakEventMessage(print_buffer)) {
3435 // Lets test script wait until break occurs to send commands. 3435 // Lets test script wait until break occurs to send commands.
3436 // Signals when a break is reported. 3436 // Signals when a break is reported.
3437 message_queue_barriers.semaphore_2->Signal(); 3437 message_queue_barriers.semaphore_2->Signal();
3438 } 3438 }
3439 3439
3440 // Allow message handler to block on a semaphore, to test queueing of 3440 // Allow message handler to block on a semaphore, to test queueing of
3441 // messages while blocked. 3441 // messages while blocked.
3442 message_queue_barriers.semaphore_1->Wait(); 3442 message_queue_barriers.semaphore_1->Wait();
3443 printf("%s\n", print_buffer); 3443 printf("%s\n", print_buffer);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3605 CHECK_EQ(2, TestClientData::destructor_call_counter); 3605 CHECK_EQ(2, TestClientData::destructor_call_counter);
3606 } 3606 }
3607 // All the client data should be destroyed when the queue is destroyed. 3607 // All the client data should be destroyed when the queue is destroyed.
3608 CHECK_EQ(TestClientData::destructor_call_counter, 3608 CHECK_EQ(TestClientData::destructor_call_counter,
3609 TestClientData::destructor_call_counter); 3609 TestClientData::destructor_call_counter);
3610 } 3610 }
3611 3611
3612 3612
3613 static int handled_client_data_instances_count = 0; 3613 static int handled_client_data_instances_count = 0;
3614 static void MessageHandlerCountingClientData( 3614 static void MessageHandlerCountingClientData(
3615 const uint16_t* message, 3615 const v8::Debug::Message& message) {
3616 int length, 3616 if (message.GetClientData() != NULL) {
3617 v8::Debug::ClientData* client_data) {
3618 if (client_data) {
3619 handled_client_data_instances_count++; 3617 handled_client_data_instances_count++;
3620 } 3618 }
3621 } 3619 }
3622 3620
3623 3621
3624 // Tests that all client data passed to the debugger are sent to the handler. 3622 // Tests that all client data passed to the debugger are sent to the handler.
3625 TEST(SendClientDataToHandler) { 3623 TEST(SendClientDataToHandler) {
3626 // Create a V8 environment 3624 // Create a V8 environment
3627 v8::HandleScope scope; 3625 v8::HandleScope scope;
3628 DebugLocalContext env; 3626 DebugLocalContext env;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 void Run(); 3682 void Run();
3685 }; 3683 };
3686 3684
3687 3685
3688 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) { 3686 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) {
3689 threaded_debugging_barriers.barrier_1.Wait(); 3687 threaded_debugging_barriers.barrier_1.Wait();
3690 return v8::Undefined(); 3688 return v8::Undefined();
3691 } 3689 }
3692 3690
3693 3691
3694 static void ThreadedMessageHandler(const uint16_t* message, int length, 3692 static void ThreadedMessageHandler(const v8::Debug::Message& message) {
3695 v8::Debug::ClientData* client_data) {
3696 static char print_buffer[1000]; 3693 static char print_buffer[1000];
3697 Utf16ToAscii(message, length, print_buffer); 3694 v8::String::Value json(message.GetJSON());
3695 Utf16ToAscii(*json, json.length(), print_buffer);
3698 if (IsBreakEventMessage(print_buffer)) { 3696 if (IsBreakEventMessage(print_buffer)) {
3699 threaded_debugging_barriers.barrier_2.Wait(); 3697 threaded_debugging_barriers.barrier_2.Wait();
3700 } 3698 }
3701 printf("%s\n", print_buffer); 3699 printf("%s\n", print_buffer);
3702 fflush(stdout); 3700 fflush(stdout);
3703 } 3701 }
3704 3702
3705 3703
3706 void V8Thread::Run() { 3704 void V8Thread::Run() {
3707 const char* source = 3705 const char* source =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3781 }; 3779 };
3782 3780
3783 class BreakpointsDebuggerThread : public v8::internal::Thread { 3781 class BreakpointsDebuggerThread : public v8::internal::Thread {
3784 public: 3782 public:
3785 void Run(); 3783 void Run();
3786 }; 3784 };
3787 3785
3788 3786
3789 Barriers* breakpoints_barriers; 3787 Barriers* breakpoints_barriers;
3790 3788
3791 static void BreakpointsMessageHandler(const uint16_t* message, 3789 static void BreakpointsMessageHandler(const v8::Debug::Message& message) {
3792 int length,
3793 v8::Debug::ClientData* client_data) {
3794 static char print_buffer[1000]; 3790 static char print_buffer[1000];
3795 Utf16ToAscii(message, length, print_buffer); 3791 v8::String::Value json(message.GetJSON());
3792 Utf16ToAscii(*json, json.length(), print_buffer);
3796 printf("%s\n", print_buffer); 3793 printf("%s\n", print_buffer);
3797 fflush(stdout); 3794 fflush(stdout);
3798 3795
3799 // Is break_template a prefix of the message? 3796 // Is break_template a prefix of the message?
3800 if (IsBreakEventMessage(print_buffer)) { 3797 if (IsBreakEventMessage(print_buffer)) {
3801 breakpoints_barriers->semaphore_1->Signal(); 3798 breakpoints_barriers->semaphore_1->Signal();
3802 } 3799 }
3803 } 3800 }
3804 3801
3805 3802
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 v8::Handle<v8::Object> event_data, 3925 v8::Handle<v8::Object> event_data,
3929 v8::Handle<v8::Value> data) { 3926 v8::Handle<v8::Value> data) {
3930 } 3927 }
3931 3928
3932 3929
3933 TEST(SetDebugEventListenerOnUninitializedVM) { 3930 TEST(SetDebugEventListenerOnUninitializedVM) {
3934 v8::Debug::SetDebugEventListener(DummyDebugEventListener); 3931 v8::Debug::SetDebugEventListener(DummyDebugEventListener);
3935 } 3932 }
3936 3933
3937 3934
3938 static void DummyMessageHandler(const uint16_t* message, 3935 static void DummyMessageHandler(const v8::Debug::Message& message) {
3939 int length,
3940 v8::Debug::ClientData* client_data) {
3941 } 3936 }
3942 3937
3943 3938
3944 TEST(SetMessageHandlerOnUninitializedVM) { 3939 TEST(SetMessageHandlerOnUninitializedVM) {
3945 v8::Debug::SetMessageHandler(DummyMessageHandler); 3940 v8::Debug::SetMessageHandler(DummyMessageHandler);
3946 } 3941 }
3947 3942
3948 3943
3949 TEST(DebugBreakOnUninitializedVM) { 3944 TEST(DebugBreakOnUninitializedVM) {
3950 v8::Debug::DebugBreak(); 3945 v8::Debug::DebugBreak();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 CHECK_EQ(2, break_point_hit_count); 4150 CHECK_EQ(2, break_point_hit_count);
4156 4151
4157 // Remove the debug event listener without clearing breakpoints again. 4152 // Remove the debug event listener without clearing breakpoints again.
4158 v8::Debug::SetDebugEventListener(NULL); 4153 v8::Debug::SetDebugEventListener(NULL);
4159 CheckDebuggerUnloaded(true); 4154 CheckDebuggerUnloaded(true);
4160 } 4155 }
4161 4156
4162 4157
4163 // Debugger message handler which counts the number of times it is called. 4158 // Debugger message handler which counts the number of times it is called.
4164 static int message_handler_hit_count = 0; 4159 static int message_handler_hit_count = 0;
4165 static void MessageHandlerHitCount(const uint16_t* message, 4160 static void MessageHandlerHitCount(const v8::Debug::Message& message) {
4166 int length,
4167 v8::Debug::ClientData* client_data) {
4168 message_handler_hit_count++; 4161 message_handler_hit_count++;
4169 4162
4170 const int kBufferSize = 1000; 4163 const int kBufferSize = 1000;
4171 uint16_t buffer[kBufferSize]; 4164 uint16_t buffer[kBufferSize];
4172 const char* command_continue = 4165 const char* command_continue =
4173 "{\"seq\":0," 4166 "{\"seq\":0,"
4174 "\"type\":\"request\"," 4167 "\"type\":\"request\","
4175 "\"command\":\"continue\"}"; 4168 "\"command\":\"continue\"}";
4176 4169
4177 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 4170 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
(...skipping 28 matching lines...) Expand all
4206 4199
4207 // The message handler should not be called more. 4200 // The message handler should not be called more.
4208 CHECK_EQ(0, message_handler_hit_count); 4201 CHECK_EQ(0, message_handler_hit_count);
4209 4202
4210 CheckDebuggerUnloaded(true); 4203 CheckDebuggerUnloaded(true);
4211 } 4204 }
4212 4205
4213 4206
4214 // Debugger message handler which clears the message handler while active. 4207 // Debugger message handler which clears the message handler while active.
4215 static void MessageHandlerClearingMessageHandler( 4208 static void MessageHandlerClearingMessageHandler(
4216 const uint16_t* message, 4209 const v8::Debug::Message& message) {
4217 int length,
4218 v8::Debug::ClientData* client_data) {
4219 message_handler_hit_count++; 4210 message_handler_hit_count++;
4220 4211
4221 // Clear debug message handler. 4212 // Clear debug message handler.
4222 v8::Debug::SetMessageHandler(NULL); 4213 v8::Debug::SetMessageHandler(NULL);
4223 } 4214 }
4224 4215
4225 4216
4226 // Test clearing the debug message handler while processing a debug event. 4217 // Test clearing the debug message handler while processing a debug event.
4227 TEST(DebuggerClearMessageHandlerWhileActive) { 4218 TEST(DebuggerClearMessageHandlerWhileActive) {
4228 v8::HandleScope scope; 4219 v8::HandleScope scope;
(...skipping 26 matching lines...) Expand all
4255 void Run(); 4246 void Run();
4256 }; 4247 };
4257 4248
4258 class HostDispatchDebuggerThread : public v8::internal::Thread { 4249 class HostDispatchDebuggerThread : public v8::internal::Thread {
4259 public: 4250 public:
4260 void Run(); 4251 void Run();
4261 }; 4252 };
4262 4253
4263 Barriers* host_dispatch_barriers; 4254 Barriers* host_dispatch_barriers;
4264 4255
4265 static void HostDispatchMessageHandler(const uint16_t* message, 4256 static void HostDispatchMessageHandler(const v8::Debug::Message& message) {
4266 int length,
4267 v8::Debug::ClientData* client_data) {
4268 static char print_buffer[1000]; 4257 static char print_buffer[1000];
4269 Utf16ToAscii(message, length, print_buffer); 4258 v8::String::Value json(message.GetJSON());
4259 Utf16ToAscii(*json, json.length(), print_buffer);
4270 printf("%s\n", print_buffer); 4260 printf("%s\n", print_buffer);
4271 fflush(stdout); 4261 fflush(stdout);
4272 } 4262 }
4273 4263
4274 4264
4275 static void HostDispatchDispatchHandler() { 4265 static void HostDispatchDispatchHandler() {
4276 host_dispatch_barriers->semaphore_1->Signal(); 4266 host_dispatch_barriers->semaphore_1->Signal();
4277 } 4267 }
4278 4268
4279 4269
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4591 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); 4581 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name"));
4592 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); 4582 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2);
4593 script2->Run(); 4583 script2->Run();
4594 script2->SetData(data_obj); 4584 script2->SetData(data_obj);
4595 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 4585 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
4596 f->Call(env->Global(), 0, NULL); 4586 f->Call(env->Global(), 0, NULL);
4597 CHECK_EQ(2, break_point_hit_count); 4587 CHECK_EQ(2, break_point_hit_count);
4598 CHECK_EQ("new name", last_script_name_hit); 4588 CHECK_EQ("new name", last_script_name_hit);
4599 CHECK_EQ("abc 123", last_script_data_hit); 4589 CHECK_EQ("abc 123", last_script_data_hit);
4600 } 4590 }
OLDNEW
« no previous file with comments | « src/debug-agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698