| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3619 } | 3619 } |
| 3620 | 3620 |
| 3621 | 3621 |
| 3622 // 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. |
| 3623 TEST(SendClientDataToHandler) { | 3623 TEST(SendClientDataToHandler) { |
| 3624 // Create a V8 environment | 3624 // Create a V8 environment |
| 3625 v8::HandleScope scope; | 3625 v8::HandleScope scope; |
| 3626 DebugLocalContext env; | 3626 DebugLocalContext env; |
| 3627 TestClientData::ResetCounters(); | 3627 TestClientData::ResetCounters(); |
| 3628 handled_client_data_instances_count = 0; | 3628 handled_client_data_instances_count = 0; |
| 3629 v8::Debug::SetMessageHandler(MessageHandlerCountingClientData); | 3629 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData); |
| 3630 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; | 3630 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; |
| 3631 const int kBufferSize = 1000; | 3631 const int kBufferSize = 1000; |
| 3632 uint16_t buffer[kBufferSize]; | 3632 uint16_t buffer[kBufferSize]; |
| 3633 const char* command_1 = | 3633 const char* command_1 = |
| 3634 "{\"seq\":117," | 3634 "{\"seq\":117," |
| 3635 "\"type\":\"request\"," | 3635 "\"type\":\"request\"," |
| 3636 "\"command\":\"evaluate\"," | 3636 "\"command\":\"evaluate\"," |
| 3637 "\"arguments\":{\"expression\":\"1+2\"}}"; | 3637 "\"arguments\":{\"expression\":\"1+2\"}}"; |
| 3638 const char* command_2 = | 3638 const char* command_2 = |
| 3639 "{\"seq\":118," | 3639 "{\"seq\":118," |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3716 " ThreadedAtBarrier1();\n" | 3716 " ThreadedAtBarrier1();\n" |
| 3717 " }\n" | 3717 " }\n" |
| 3718 " x = x + 1;\n" | 3718 " x = x + 1;\n" |
| 3719 " }\n" | 3719 " }\n" |
| 3720 "}\n" | 3720 "}\n" |
| 3721 "\n" | 3721 "\n" |
| 3722 "foo();\n"; | 3722 "foo();\n"; |
| 3723 | 3723 |
| 3724 v8::HandleScope scope; | 3724 v8::HandleScope scope; |
| 3725 DebugLocalContext env; | 3725 DebugLocalContext env; |
| 3726 v8::Debug::SetMessageHandler(&ThreadedMessageHandler); | 3726 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); |
| 3727 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 3727 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 3728 global_template->Set(v8::String::New("ThreadedAtBarrier1"), | 3728 global_template->Set(v8::String::New("ThreadedAtBarrier1"), |
| 3729 v8::FunctionTemplate::New(ThreadedAtBarrier1)); | 3729 v8::FunctionTemplate::New(ThreadedAtBarrier1)); |
| 3730 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); | 3730 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); |
| 3731 v8::Context::Scope context_scope(context); | 3731 v8::Context::Scope context_scope(context); |
| 3732 | 3732 |
| 3733 CompileRun(source); | 3733 CompileRun(source); |
| 3734 } | 3734 } |
| 3735 | 3735 |
| 3736 void DebuggerThread::Run() { | 3736 void DebuggerThread::Run() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3816 " var z = 3;" | 3816 " var z = 3;" |
| 3817 " x += 100;\n" | 3817 " x += 100;\n" |
| 3818 " return x;\n" | 3818 " return x;\n" |
| 3819 "}\n" | 3819 "}\n" |
| 3820 "\n"; | 3820 "\n"; |
| 3821 const char* source_2 = "cat(17);\n" | 3821 const char* source_2 = "cat(17);\n" |
| 3822 "cat(19);\n"; | 3822 "cat(19);\n"; |
| 3823 | 3823 |
| 3824 v8::HandleScope scope; | 3824 v8::HandleScope scope; |
| 3825 DebugLocalContext env; | 3825 DebugLocalContext env; |
| 3826 v8::Debug::SetMessageHandler(&BreakpointsMessageHandler); | 3826 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler); |
| 3827 | 3827 |
| 3828 CompileRun(source_1); | 3828 CompileRun(source_1); |
| 3829 breakpoints_barriers->barrier_1.Wait(); | 3829 breakpoints_barriers->barrier_1.Wait(); |
| 3830 breakpoints_barriers->barrier_2.Wait(); | 3830 breakpoints_barriers->barrier_2.Wait(); |
| 3831 CompileRun(source_2); | 3831 CompileRun(source_2); |
| 3832 } | 3832 } |
| 3833 | 3833 |
| 3834 | 3834 |
| 3835 void BreakpointsDebuggerThread::Run() { | 3835 void BreakpointsDebuggerThread::Run() { |
| 3836 const int kBufSize = 1000; | 3836 const int kBufSize = 1000; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3930 TEST(SetDebugEventListenerOnUninitializedVM) { | 3930 TEST(SetDebugEventListenerOnUninitializedVM) { |
| 3931 v8::Debug::SetDebugEventListener(DummyDebugEventListener); | 3931 v8::Debug::SetDebugEventListener(DummyDebugEventListener); |
| 3932 } | 3932 } |
| 3933 | 3933 |
| 3934 | 3934 |
| 3935 static void DummyMessageHandler(const v8::Debug::Message& message) { | 3935 static void DummyMessageHandler(const v8::Debug::Message& message) { |
| 3936 } | 3936 } |
| 3937 | 3937 |
| 3938 | 3938 |
| 3939 TEST(SetMessageHandlerOnUninitializedVM) { | 3939 TEST(SetMessageHandlerOnUninitializedVM) { |
| 3940 v8::Debug::SetMessageHandler(DummyMessageHandler); | 3940 v8::Debug::SetMessageHandler2(DummyMessageHandler); |
| 3941 } | 3941 } |
| 3942 | 3942 |
| 3943 | 3943 |
| 3944 TEST(DebugBreakOnUninitializedVM) { | 3944 TEST(DebugBreakOnUninitializedVM) { |
| 3945 v8::Debug::DebugBreak(); | 3945 v8::Debug::DebugBreak(); |
| 3946 } | 3946 } |
| 3947 | 3947 |
| 3948 | 3948 |
| 3949 TEST(SendCommandToUninitializedVM) { | 3949 TEST(SendCommandToUninitializedVM) { |
| 3950 const char* dummy_command = "{}"; | 3950 const char* dummy_command = "{}"; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4173 | 4173 |
| 4174 // Test clearing the debug message handler. | 4174 // Test clearing the debug message handler. |
| 4175 TEST(DebuggerClearMessageHandler) { | 4175 TEST(DebuggerClearMessageHandler) { |
| 4176 v8::HandleScope scope; | 4176 v8::HandleScope scope; |
| 4177 DebugLocalContext env; | 4177 DebugLocalContext env; |
| 4178 | 4178 |
| 4179 // Check debugger is unloaded before it is used. | 4179 // Check debugger is unloaded before it is used. |
| 4180 CheckDebuggerUnloaded(); | 4180 CheckDebuggerUnloaded(); |
| 4181 | 4181 |
| 4182 // Set a debug message handler. | 4182 // Set a debug message handler. |
| 4183 v8::Debug::SetMessageHandler(MessageHandlerHitCount); | 4183 v8::Debug::SetMessageHandler2(MessageHandlerHitCount); |
| 4184 | 4184 |
| 4185 // Run code to throw a unhandled exception. This should end up in the message | 4185 // Run code to throw a unhandled exception. This should end up in the message |
| 4186 // handler. | 4186 // handler. |
| 4187 CompileRun("throw 1"); | 4187 CompileRun("throw 1"); |
| 4188 | 4188 |
| 4189 // The message handler should be called. | 4189 // The message handler should be called. |
| 4190 CHECK_GT(message_handler_hit_count, 0); | 4190 CHECK_GT(message_handler_hit_count, 0); |
| 4191 | 4191 |
| 4192 // Clear debug message handler. | 4192 // Clear debug message handler. |
| 4193 message_handler_hit_count = 0; | 4193 message_handler_hit_count = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4216 | 4216 |
| 4217 // Test clearing the debug message handler while processing a debug event. | 4217 // Test clearing the debug message handler while processing a debug event. |
| 4218 TEST(DebuggerClearMessageHandlerWhileActive) { | 4218 TEST(DebuggerClearMessageHandlerWhileActive) { |
| 4219 v8::HandleScope scope; | 4219 v8::HandleScope scope; |
| 4220 DebugLocalContext env; | 4220 DebugLocalContext env; |
| 4221 | 4221 |
| 4222 // Check debugger is unloaded before it is used. | 4222 // Check debugger is unloaded before it is used. |
| 4223 CheckDebuggerUnloaded(); | 4223 CheckDebuggerUnloaded(); |
| 4224 | 4224 |
| 4225 // Set a debug message handler. | 4225 // Set a debug message handler. |
| 4226 v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler); | 4226 v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler); |
| 4227 | 4227 |
| 4228 // Run code to throw a unhandled exception. This should end up in the message | 4228 // Run code to throw a unhandled exception. This should end up in the message |
| 4229 // handler. | 4229 // handler. |
| 4230 CompileRun("throw 1"); | 4230 CompileRun("throw 1"); |
| 4231 | 4231 |
| 4232 // The message handler should be called. | 4232 // The message handler should be called. |
| 4233 CHECK_EQ(1, message_handler_hit_count); | 4233 CHECK_EQ(1, message_handler_hit_count); |
| 4234 | 4234 |
| 4235 CheckDebuggerUnloaded(true); | 4235 CheckDebuggerUnloaded(true); |
| 4236 } | 4236 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4276 " y_global = 5;\n" | 4276 " y_global = 5;\n" |
| 4277 " return x;\n" | 4277 " return x;\n" |
| 4278 "}\n" | 4278 "}\n" |
| 4279 "\n"; | 4279 "\n"; |
| 4280 const char* source_2 = "cat(17);\n"; | 4280 const char* source_2 = "cat(17);\n"; |
| 4281 | 4281 |
| 4282 v8::HandleScope scope; | 4282 v8::HandleScope scope; |
| 4283 DebugLocalContext env; | 4283 DebugLocalContext env; |
| 4284 | 4284 |
| 4285 // Setup message and host dispatch handlers. | 4285 // Setup message and host dispatch handlers. |
| 4286 v8::Debug::SetMessageHandler(HostDispatchMessageHandler); | 4286 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler); |
| 4287 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */); | 4287 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */); |
| 4288 | 4288 |
| 4289 CompileRun(source_1); | 4289 CompileRun(source_1); |
| 4290 host_dispatch_barriers->barrier_1.Wait(); | 4290 host_dispatch_barriers->barrier_1.Wait(); |
| 4291 host_dispatch_barriers->barrier_2.Wait(); | 4291 host_dispatch_barriers->barrier_2.Wait(); |
| 4292 CompileRun(source_2); | 4292 CompileRun(source_2); |
| 4293 } | 4293 } |
| 4294 | 4294 |
| 4295 | 4295 |
| 4296 void HostDispatchDebuggerThread::Run() { | 4296 void HostDispatchDebuggerThread::Run() { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4581 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); | 4581 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); |
| 4582 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 4582 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
| 4583 script2->Run(); | 4583 script2->Run(); |
| 4584 script2->SetData(data_obj); | 4584 script2->SetData(data_obj); |
| 4585 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"))); |
| 4586 f->Call(env->Global(), 0, NULL); | 4586 f->Call(env->Global(), 0, NULL); |
| 4587 CHECK_EQ(2, break_point_hit_count); | 4587 CHECK_EQ(2, break_point_hit_count); |
| 4588 CHECK_EQ("new name", last_script_name_hit); | 4588 CHECK_EQ("new name", last_script_name_hit); |
| 4589 CHECK_EQ("abc 123", last_script_data_hit); | 4589 CHECK_EQ("abc 123", last_script_data_hit); |
| 4590 } | 4590 } |
| OLD | NEW |