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 6270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6281 } | 6281 } |
6282 | 6282 |
6283 | 6283 |
6284 // Test which creates two contexts and sets different embedder data on each. | 6284 // Test which creates two contexts and sets different embedder data on each. |
6285 // Checks that this data is set correctly and that when the debug message | 6285 // Checks that this data is set correctly and that when the debug message |
6286 // handler is called the expected context is the one active. | 6286 // handler is called the expected context is the one active. |
6287 TEST(ContextData) { | 6287 TEST(ContextData) { |
6288 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 6288 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
6289 v8::HandleScope scope(isolate); | 6289 v8::HandleScope scope(isolate); |
6290 | 6290 |
6291 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); | |
6292 | |
6293 // Create two contexts. | 6291 // Create two contexts. |
6294 v8::Handle<v8::Context> context_1; | 6292 v8::Handle<v8::Context> context_1; |
6295 v8::Handle<v8::Context> context_2; | 6293 v8::Handle<v8::Context> context_2; |
6296 v8::Handle<v8::ObjectTemplate> global_template = | 6294 v8::Handle<v8::ObjectTemplate> global_template = |
6297 v8::Handle<v8::ObjectTemplate>(); | 6295 v8::Handle<v8::ObjectTemplate>(); |
6298 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); | 6296 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>(); |
6299 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); | 6297 context_1 = v8::Context::New(isolate, NULL, global_template, global_object); |
6300 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); | 6298 context_2 = v8::Context::New(isolate, NULL, global_template, global_object); |
6301 | 6299 |
| 6300 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); |
| 6301 |
6302 // Default data value is undefined. | 6302 // Default data value is undefined. |
6303 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6303 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6304 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); | 6304 CHECK(context_2->GetEmbedderData(0)->IsUndefined()); |
6305 | 6305 |
6306 // Set and check different data values. | 6306 // Set and check different data values. |
6307 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6307 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6308 v8::Handle<v8::String> data_2 = v8::String::New("2"); | 6308 v8::Handle<v8::String> data_2 = v8::String::New("2"); |
6309 context_1->SetEmbedderData(0, data_1); | 6309 context_1->SetEmbedderData(0, data_1); |
6310 context_2->SetEmbedderData(0, data_2); | 6310 context_2->SetEmbedderData(0, data_2); |
6311 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6311 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6449 | 6449 |
6450 // Check that there was only one break event. Matching RegExp should not | 6450 // Check that there was only one break event. Matching RegExp should not |
6451 // cause Break events. | 6451 // cause Break events. |
6452 CHECK_EQ(1, break_point_hit_count); | 6452 CHECK_EQ(1, break_point_hit_count); |
6453 CHECK_EQ("f", last_function_hit); | 6453 CHECK_EQ("f", last_function_hit); |
6454 } | 6454 } |
6455 #endif // V8_INTERPRETED_REGEXP | 6455 #endif // V8_INTERPRETED_REGEXP |
6456 | 6456 |
6457 | 6457 |
6458 // Common part of EvalContextData and NestedBreakEventContextData tests. | 6458 // Common part of EvalContextData and NestedBreakEventContextData tests. |
6459 static void ExecuteScriptForContextCheck() { | 6459 static void ExecuteScriptForContextCheck( |
| 6460 v8::Debug::MessageHandler2 message_handler) { |
6460 // Create a context. | 6461 // Create a context. |
6461 v8::Handle<v8::Context> context_1; | 6462 v8::Handle<v8::Context> context_1; |
6462 v8::Handle<v8::ObjectTemplate> global_template = | 6463 v8::Handle<v8::ObjectTemplate> global_template = |
6463 v8::Handle<v8::ObjectTemplate>(); | 6464 v8::Handle<v8::ObjectTemplate>(); |
6464 context_1 = | 6465 context_1 = |
6465 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global_template); | 6466 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global_template); |
6466 | 6467 |
| 6468 v8::Debug::SetMessageHandler2(message_handler); |
| 6469 |
6467 // Default data value is undefined. | 6470 // Default data value is undefined. |
6468 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); | 6471 CHECK(context_1->GetEmbedderData(0)->IsUndefined()); |
6469 | 6472 |
6470 // Set and check a data value. | 6473 // Set and check a data value. |
6471 v8::Handle<v8::String> data_1 = v8::String::New("1"); | 6474 v8::Handle<v8::String> data_1 = v8::String::New("1"); |
6472 context_1->SetEmbedderData(0, data_1); | 6475 context_1->SetEmbedderData(0, data_1); |
6473 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); | 6476 CHECK(context_1->GetEmbedderData(0)->StrictEquals(data_1)); |
6474 | 6477 |
6475 // Simple test function with eval that causes a break. | 6478 // Simple test function with eval that causes a break. |
6476 const char* source = "function f() { eval('debugger;'); }"; | 6479 const char* source = "function f() { eval('debugger;'); }"; |
6477 | 6480 |
6478 // Enter and run function in the context. | 6481 // Enter and run function in the context. |
6479 { | 6482 { |
6480 v8::Context::Scope context_scope(context_1); | 6483 v8::Context::Scope context_scope(context_1); |
6481 expected_context = context_1; | 6484 expected_context = context_1; |
6482 expected_context_data = data_1; | 6485 expected_context_data = data_1; |
6483 v8::Local<v8::Function> f = CompileFunction(source, "f"); | 6486 v8::Local<v8::Function> f = CompileFunction(source, "f"); |
6484 f->Call(context_1->Global(), 0, NULL); | 6487 f->Call(context_1->Global(), 0, NULL); |
6485 } | 6488 } |
| 6489 |
| 6490 v8::Debug::SetMessageHandler2(NULL); |
6486 } | 6491 } |
6487 | 6492 |
6488 | 6493 |
6489 // Test which creates a context and sets embedder data on it. Checks that this | 6494 // Test which creates a context and sets embedder data on it. Checks that this |
6490 // data is set correctly and that when the debug message handler is called for | 6495 // data is set correctly and that when the debug message handler is called for |
6491 // break event in an eval statement the expected context is the one returned by | 6496 // break event in an eval statement the expected context is the one returned by |
6492 // Message.GetEventContext. | 6497 // Message.GetEventContext. |
6493 TEST(EvalContextData) { | 6498 TEST(EvalContextData) { |
6494 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 6499 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
6495 v8::Debug::SetMessageHandler2(ContextCheckMessageHandler); | |
6496 | 6500 |
6497 ExecuteScriptForContextCheck(); | 6501 ExecuteScriptForContextCheck(ContextCheckMessageHandler); |
6498 | 6502 |
6499 // One time compile event and one time break event. | 6503 // One time compile event and one time break event. |
6500 CHECK_GT(message_handler_hit_count, 2); | 6504 CHECK_GT(message_handler_hit_count, 2); |
6501 v8::Debug::SetMessageHandler2(NULL); | |
6502 CheckDebuggerUnloaded(); | 6505 CheckDebuggerUnloaded(); |
6503 } | 6506 } |
6504 | 6507 |
6505 | 6508 |
6506 static bool sent_eval = false; | 6509 static bool sent_eval = false; |
6507 static int break_count = 0; | 6510 static int break_count = 0; |
6508 static int continue_command_send_count = 0; | 6511 static int continue_command_send_count = 0; |
6509 // Check that the expected context is the one generating the debug event | 6512 // Check that the expected context is the one generating the debug event |
6510 // including the case of nested break event. | 6513 // including the case of nested break event. |
6511 static void DebugEvalContextCheckMessageHandler( | 6514 static void DebugEvalContextCheckMessageHandler( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6550 } | 6553 } |
6551 } | 6554 } |
6552 | 6555 |
6553 | 6556 |
6554 // Tests that context returned for break event is correct when the event occurs | 6557 // Tests that context returned for break event is correct when the event occurs |
6555 // in 'evaluate' debugger request. | 6558 // in 'evaluate' debugger request. |
6556 TEST(NestedBreakEventContextData) { | 6559 TEST(NestedBreakEventContextData) { |
6557 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 6560 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
6558 break_count = 0; | 6561 break_count = 0; |
6559 message_handler_hit_count = 0; | 6562 message_handler_hit_count = 0; |
6560 v8::Debug::SetMessageHandler2(DebugEvalContextCheckMessageHandler); | |
6561 | 6563 |
6562 ExecuteScriptForContextCheck(); | 6564 ExecuteScriptForContextCheck(DebugEvalContextCheckMessageHandler); |
6563 | 6565 |
6564 // One time compile event and two times break event. | 6566 // One time compile event and two times break event. |
6565 CHECK_GT(message_handler_hit_count, 3); | 6567 CHECK_GT(message_handler_hit_count, 3); |
6566 | 6568 |
6567 // One break from the source and another from the evaluate request. | 6569 // One break from the source and another from the evaluate request. |
6568 CHECK_EQ(break_count, 2); | 6570 CHECK_EQ(break_count, 2); |
6569 v8::Debug::SetMessageHandler2(NULL); | |
6570 CheckDebuggerUnloaded(); | 6571 CheckDebuggerUnloaded(); |
6571 } | 6572 } |
6572 | 6573 |
6573 | 6574 |
6574 // Debug event listener which counts the script collected events. | 6575 // Debug event listener which counts the script collected events. |
6575 int script_collected_count = 0; | 6576 int script_collected_count = 0; |
6576 static void DebugEventScriptCollectedEvent(v8::DebugEvent event, | 6577 static void DebugEventScriptCollectedEvent(v8::DebugEvent event, |
6577 v8::Handle<v8::Object> exec_state, | 6578 v8::Handle<v8::Object> exec_state, |
6578 v8::Handle<v8::Object> event_data, | 6579 v8::Handle<v8::Object> event_data, |
6579 v8::Handle<v8::Value> data) { | 6580 v8::Handle<v8::Value> data) { |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7130 CHECK(details.GetEventContext() == expected_context); | 7131 CHECK(details.GetEventContext() == expected_context); |
7131 CHECK_EQ(expected_callback_data, details.GetCallbackData()); | 7132 CHECK_EQ(expected_callback_data, details.GetCallbackData()); |
7132 } | 7133 } |
7133 | 7134 |
7134 | 7135 |
7135 // Check that event details contain context where debug event occured. | 7136 // Check that event details contain context where debug event occured. |
7136 TEST(DebugEventContext) { | 7137 TEST(DebugEventContext) { |
7137 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 7138 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
7138 v8::HandleScope scope(isolate); | 7139 v8::HandleScope scope(isolate); |
7139 expected_callback_data = v8::Int32::New(2010); | 7140 expected_callback_data = v8::Int32::New(2010); |
| 7141 expected_context = v8::Context::New(isolate); |
7140 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, | 7142 v8::Debug::SetDebugEventListener2(DebugEventContextChecker, |
7141 expected_callback_data); | 7143 expected_callback_data); |
7142 expected_context = v8::Context::New(isolate); | |
7143 v8::Context::Scope context_scope(expected_context); | 7144 v8::Context::Scope context_scope(expected_context); |
7144 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); | 7145 v8::Script::Compile(v8::String::New("(function(){debugger;})();"))->Run(); |
7145 expected_context.Clear(); | 7146 expected_context.Clear(); |
7146 v8::Debug::SetDebugEventListener(NULL); | 7147 v8::Debug::SetDebugEventListener(NULL); |
7147 expected_context_data = v8::Handle<v8::Value>(); | 7148 expected_context_data = v8::Handle<v8::Value>(); |
7148 CheckDebuggerUnloaded(); | 7149 CheckDebuggerUnloaded(); |
7149 } | 7150 } |
7150 | 7151 |
7151 | 7152 |
7152 static void* expected_break_data; | 7153 static void* expected_break_data; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7594 TEST(LiveEditDisabled) { | 7595 TEST(LiveEditDisabled) { |
7595 v8::internal::FLAG_allow_natives_syntax = true; | 7596 v8::internal::FLAG_allow_natives_syntax = true; |
7596 LocalContext env; | 7597 LocalContext env; |
7597 v8::HandleScope scope(env->GetIsolate()); | 7598 v8::HandleScope scope(env->GetIsolate()); |
7598 v8::Debug::SetLiveEditEnabled(false); | 7599 v8::Debug::SetLiveEditEnabled(false); |
7599 CompileRun("%LiveEditCompareStrings('', '')"); | 7600 CompileRun("%LiveEditCompareStrings('', '')"); |
7600 } | 7601 } |
7601 | 7602 |
7602 | 7603 |
7603 #endif // ENABLE_DEBUGGER_SUPPORT | 7604 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |