| OLD | NEW |
| 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 Loading... |
| 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 v8::Debug::Message& message) { | 3430 static void MessageHandler(const uint16_t* message, int length, |
| 3431 v8::Debug::ClientData* client_data) { |
| 3431 static char print_buffer[1000]; | 3432 static char print_buffer[1000]; |
| 3432 v8::String::Value json(message.GetJSON()); | 3433 Utf16ToAscii(message, length, print_buffer); |
| 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 Loading... |
| 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 v8::Debug::Message& message) { | 3615 const uint16_t* message, |
| 3616 if (message.GetClientData() != NULL) { | 3616 int length, |
| 3617 v8::Debug::ClientData* client_data) { |
| 3618 if (client_data) { |
| 3617 handled_client_data_instances_count++; | 3619 handled_client_data_instances_count++; |
| 3618 } | 3620 } |
| 3619 } | 3621 } |
| 3620 | 3622 |
| 3621 | 3623 |
| 3622 // Tests that all client data passed to the debugger are sent to the handler. | 3624 // Tests that all client data passed to the debugger are sent to the handler. |
| 3623 TEST(SendClientDataToHandler) { | 3625 TEST(SendClientDataToHandler) { |
| 3624 // Create a V8 environment | 3626 // Create a V8 environment |
| 3625 v8::HandleScope scope; | 3627 v8::HandleScope scope; |
| 3626 DebugLocalContext env; | 3628 DebugLocalContext env; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3682 void Run(); | 3684 void Run(); |
| 3683 }; | 3685 }; |
| 3684 | 3686 |
| 3685 | 3687 |
| 3686 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) { | 3688 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) { |
| 3687 threaded_debugging_barriers.barrier_1.Wait(); | 3689 threaded_debugging_barriers.barrier_1.Wait(); |
| 3688 return v8::Undefined(); | 3690 return v8::Undefined(); |
| 3689 } | 3691 } |
| 3690 | 3692 |
| 3691 | 3693 |
| 3692 static void ThreadedMessageHandler(const v8::Debug::Message& message) { | 3694 static void ThreadedMessageHandler(const uint16_t* message, int length, |
| 3695 v8::Debug::ClientData* client_data) { |
| 3693 static char print_buffer[1000]; | 3696 static char print_buffer[1000]; |
| 3694 v8::String::Value json(message.GetJSON()); | 3697 Utf16ToAscii(message, length, print_buffer); |
| 3695 Utf16ToAscii(*json, json.length(), print_buffer); | |
| 3696 if (IsBreakEventMessage(print_buffer)) { | 3698 if (IsBreakEventMessage(print_buffer)) { |
| 3697 threaded_debugging_barriers.barrier_2.Wait(); | 3699 threaded_debugging_barriers.barrier_2.Wait(); |
| 3698 } | 3700 } |
| 3699 printf("%s\n", print_buffer); | 3701 printf("%s\n", print_buffer); |
| 3700 fflush(stdout); | 3702 fflush(stdout); |
| 3701 } | 3703 } |
| 3702 | 3704 |
| 3703 | 3705 |
| 3704 void V8Thread::Run() { | 3706 void V8Thread::Run() { |
| 3705 const char* source = | 3707 const char* source = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3779 }; | 3781 }; |
| 3780 | 3782 |
| 3781 class BreakpointsDebuggerThread : public v8::internal::Thread { | 3783 class BreakpointsDebuggerThread : public v8::internal::Thread { |
| 3782 public: | 3784 public: |
| 3783 void Run(); | 3785 void Run(); |
| 3784 }; | 3786 }; |
| 3785 | 3787 |
| 3786 | 3788 |
| 3787 Barriers* breakpoints_barriers; | 3789 Barriers* breakpoints_barriers; |
| 3788 | 3790 |
| 3789 static void BreakpointsMessageHandler(const v8::Debug::Message& message) { | 3791 static void BreakpointsMessageHandler(const uint16_t* message, |
| 3792 int length, |
| 3793 v8::Debug::ClientData* client_data) { |
| 3790 static char print_buffer[1000]; | 3794 static char print_buffer[1000]; |
| 3791 v8::String::Value json(message.GetJSON()); | 3795 Utf16ToAscii(message, length, print_buffer); |
| 3792 Utf16ToAscii(*json, json.length(), print_buffer); | |
| 3793 printf("%s\n", print_buffer); | 3796 printf("%s\n", print_buffer); |
| 3794 fflush(stdout); | 3797 fflush(stdout); |
| 3795 | 3798 |
| 3796 // Is break_template a prefix of the message? | 3799 // Is break_template a prefix of the message? |
| 3797 if (IsBreakEventMessage(print_buffer)) { | 3800 if (IsBreakEventMessage(print_buffer)) { |
| 3798 breakpoints_barriers->semaphore_1->Signal(); | 3801 breakpoints_barriers->semaphore_1->Signal(); |
| 3799 } | 3802 } |
| 3800 } | 3803 } |
| 3801 | 3804 |
| 3802 | 3805 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3925 v8::Handle<v8::Object> event_data, | 3928 v8::Handle<v8::Object> event_data, |
| 3926 v8::Handle<v8::Value> data) { | 3929 v8::Handle<v8::Value> data) { |
| 3927 } | 3930 } |
| 3928 | 3931 |
| 3929 | 3932 |
| 3930 TEST(SetDebugEventListenerOnUninitializedVM) { | 3933 TEST(SetDebugEventListenerOnUninitializedVM) { |
| 3931 v8::Debug::SetDebugEventListener(DummyDebugEventListener); | 3934 v8::Debug::SetDebugEventListener(DummyDebugEventListener); |
| 3932 } | 3935 } |
| 3933 | 3936 |
| 3934 | 3937 |
| 3935 static void DummyMessageHandler(const v8::Debug::Message& message) { | 3938 static void DummyMessageHandler(const uint16_t* message, |
| 3939 int length, |
| 3940 v8::Debug::ClientData* client_data) { |
| 3936 } | 3941 } |
| 3937 | 3942 |
| 3938 | 3943 |
| 3939 TEST(SetMessageHandlerOnUninitializedVM) { | 3944 TEST(SetMessageHandlerOnUninitializedVM) { |
| 3940 v8::Debug::SetMessageHandler(DummyMessageHandler); | 3945 v8::Debug::SetMessageHandler(DummyMessageHandler); |
| 3941 } | 3946 } |
| 3942 | 3947 |
| 3943 | 3948 |
| 3944 TEST(DebugBreakOnUninitializedVM) { | 3949 TEST(DebugBreakOnUninitializedVM) { |
| 3945 v8::Debug::DebugBreak(); | 3950 v8::Debug::DebugBreak(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4150 CHECK_EQ(2, break_point_hit_count); | 4155 CHECK_EQ(2, break_point_hit_count); |
| 4151 | 4156 |
| 4152 // Remove the debug event listener without clearing breakpoints again. | 4157 // Remove the debug event listener without clearing breakpoints again. |
| 4153 v8::Debug::SetDebugEventListener(NULL); | 4158 v8::Debug::SetDebugEventListener(NULL); |
| 4154 CheckDebuggerUnloaded(true); | 4159 CheckDebuggerUnloaded(true); |
| 4155 } | 4160 } |
| 4156 | 4161 |
| 4157 | 4162 |
| 4158 // Debugger message handler which counts the number of times it is called. | 4163 // Debugger message handler which counts the number of times it is called. |
| 4159 static int message_handler_hit_count = 0; | 4164 static int message_handler_hit_count = 0; |
| 4160 static void MessageHandlerHitCount(const v8::Debug::Message& message) { | 4165 static void MessageHandlerHitCount(const uint16_t* message, |
| 4166 int length, |
| 4167 v8::Debug::ClientData* client_data) { |
| 4161 message_handler_hit_count++; | 4168 message_handler_hit_count++; |
| 4162 | 4169 |
| 4163 const int kBufferSize = 1000; | 4170 const int kBufferSize = 1000; |
| 4164 uint16_t buffer[kBufferSize]; | 4171 uint16_t buffer[kBufferSize]; |
| 4165 const char* command_continue = | 4172 const char* command_continue = |
| 4166 "{\"seq\":0," | 4173 "{\"seq\":0," |
| 4167 "\"type\":\"request\"," | 4174 "\"type\":\"request\"," |
| 4168 "\"command\":\"continue\"}"; | 4175 "\"command\":\"continue\"}"; |
| 4169 | 4176 |
| 4170 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 4177 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4199 | 4206 |
| 4200 // The message handler should not be called more. | 4207 // The message handler should not be called more. |
| 4201 CHECK_EQ(0, message_handler_hit_count); | 4208 CHECK_EQ(0, message_handler_hit_count); |
| 4202 | 4209 |
| 4203 CheckDebuggerUnloaded(true); | 4210 CheckDebuggerUnloaded(true); |
| 4204 } | 4211 } |
| 4205 | 4212 |
| 4206 | 4213 |
| 4207 // Debugger message handler which clears the message handler while active. | 4214 // Debugger message handler which clears the message handler while active. |
| 4208 static void MessageHandlerClearingMessageHandler( | 4215 static void MessageHandlerClearingMessageHandler( |
| 4209 const v8::Debug::Message& message) { | 4216 const uint16_t* message, |
| 4217 int length, |
| 4218 v8::Debug::ClientData* client_data) { |
| 4210 message_handler_hit_count++; | 4219 message_handler_hit_count++; |
| 4211 | 4220 |
| 4212 // Clear debug message handler. | 4221 // Clear debug message handler. |
| 4213 v8::Debug::SetMessageHandler(NULL); | 4222 v8::Debug::SetMessageHandler(NULL); |
| 4214 } | 4223 } |
| 4215 | 4224 |
| 4216 | 4225 |
| 4217 // Test clearing the debug message handler while processing a debug event. | 4226 // Test clearing the debug message handler while processing a debug event. |
| 4218 TEST(DebuggerClearMessageHandlerWhileActive) { | 4227 TEST(DebuggerClearMessageHandlerWhileActive) { |
| 4219 v8::HandleScope scope; | 4228 v8::HandleScope scope; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4246 void Run(); | 4255 void Run(); |
| 4247 }; | 4256 }; |
| 4248 | 4257 |
| 4249 class HostDispatchDebuggerThread : public v8::internal::Thread { | 4258 class HostDispatchDebuggerThread : public v8::internal::Thread { |
| 4250 public: | 4259 public: |
| 4251 void Run(); | 4260 void Run(); |
| 4252 }; | 4261 }; |
| 4253 | 4262 |
| 4254 Barriers* host_dispatch_barriers; | 4263 Barriers* host_dispatch_barriers; |
| 4255 | 4264 |
| 4256 static void HostDispatchMessageHandler(const v8::Debug::Message& message) { | 4265 static void HostDispatchMessageHandler(const uint16_t* message, |
| 4266 int length, |
| 4267 v8::Debug::ClientData* client_data) { |
| 4257 static char print_buffer[1000]; | 4268 static char print_buffer[1000]; |
| 4258 v8::String::Value json(message.GetJSON()); | 4269 Utf16ToAscii(message, length, print_buffer); |
| 4259 Utf16ToAscii(*json, json.length(), print_buffer); | |
| 4260 printf("%s\n", print_buffer); | 4270 printf("%s\n", print_buffer); |
| 4261 fflush(stdout); | 4271 fflush(stdout); |
| 4262 } | 4272 } |
| 4263 | 4273 |
| 4264 | 4274 |
| 4265 static void HostDispatchDispatchHandler() { | 4275 static void HostDispatchDispatchHandler() { |
| 4266 host_dispatch_barriers->semaphore_1->Signal(); | 4276 host_dispatch_barriers->semaphore_1->Signal(); |
| 4267 } | 4277 } |
| 4268 | 4278 |
| 4269 | 4279 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4581 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); | 4591 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); |
| 4582 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 4592 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
| 4583 script2->Run(); | 4593 script2->Run(); |
| 4584 script2->SetData(data_obj); | 4594 script2->SetData(data_obj); |
| 4585 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 4595 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 4586 f->Call(env->Global(), 0, NULL); | 4596 f->Call(env->Global(), 0, NULL); |
| 4587 CHECK_EQ(2, break_point_hit_count); | 4597 CHECK_EQ(2, break_point_hit_count); |
| 4588 CHECK_EQ("new name", last_script_name_hit); | 4598 CHECK_EQ("new name", last_script_name_hit); |
| 4589 CHECK_EQ("abc 123", last_script_data_hit); | 4599 CHECK_EQ("abc 123", last_script_data_hit); |
| 4590 } | 4600 } |
| OLD | NEW |