| 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 6203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6214 | 6214 |
| 6215 // One time compile event and two times break event. | 6215 // One time compile event and two times break event. |
| 6216 CHECK_GT(message_handler_hit_count, 3); | 6216 CHECK_GT(message_handler_hit_count, 3); |
| 6217 | 6217 |
| 6218 // One break from the source and another from the evaluate request. | 6218 // One break from the source and another from the evaluate request. |
| 6219 CHECK_EQ(break_count, 2); | 6219 CHECK_EQ(break_count, 2); |
| 6220 CheckDebuggerUnloaded(); | 6220 CheckDebuggerUnloaded(); |
| 6221 } | 6221 } |
| 6222 | 6222 |
| 6223 | 6223 |
| 6224 // Debug event listener which counts the script collected events. | |
| 6225 int script_collected_count = 0; | |
| 6226 static void DebugEventScriptCollectedEvent( | |
| 6227 const v8::Debug::EventDetails& event_details) { | |
| 6228 v8::DebugEvent event = event_details.GetEvent(); | |
| 6229 // Count the number of breaks. | |
| 6230 if (event == v8::ScriptCollected) { | |
| 6231 script_collected_count++; | |
| 6232 } | |
| 6233 } | |
| 6234 | |
| 6235 | |
| 6236 // Test that scripts collected are reported through the debug event listener. | |
| 6237 TEST(ScriptCollectedEvent) { | |
| 6238 v8::internal::Debug* debug = CcTest::i_isolate()->debug(); | |
| 6239 break_point_hit_count = 0; | |
| 6240 script_collected_count = 0; | |
| 6241 DebugLocalContext env; | |
| 6242 v8::HandleScope scope(env->GetIsolate()); | |
| 6243 | |
| 6244 // Request the loaded scripts to initialize the debugger script cache. | |
| 6245 debug->GetLoadedScripts(); | |
| 6246 | |
| 6247 // Do garbage collection to ensure that only the script in this test will be | |
| 6248 // collected afterwards. | |
| 6249 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 6250 | |
| 6251 script_collected_count = 0; | |
| 6252 v8::Debug::SetDebugEventListener(DebugEventScriptCollectedEvent); | |
| 6253 { | |
| 6254 v8::Script::Compile( | |
| 6255 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=1')"))->Run(); | |
| 6256 v8::Script::Compile( | |
| 6257 v8::String::NewFromUtf8(env->GetIsolate(), "eval('a=2')"))->Run(); | |
| 6258 } | |
| 6259 | |
| 6260 // Do garbage collection to collect the script above which is no longer | |
| 6261 // referenced. | |
| 6262 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 6263 | |
| 6264 CHECK_EQ(2, script_collected_count); | |
| 6265 | |
| 6266 v8::Debug::SetDebugEventListener(NULL); | |
| 6267 CheckDebuggerUnloaded(); | |
| 6268 } | |
| 6269 | |
| 6270 | |
| 6271 // Debug event listener which counts the script collected events. | |
| 6272 int script_collected_message_count = 0; | |
| 6273 static void ScriptCollectedMessageHandler(const v8::Debug::Message& message) { | |
| 6274 // Count the number of scripts collected. | |
| 6275 if (message.IsEvent() && message.GetEvent() == v8::ScriptCollected) { | |
| 6276 script_collected_message_count++; | |
| 6277 v8::Handle<v8::Context> context = message.GetEventContext(); | |
| 6278 CHECK(context.IsEmpty()); | |
| 6279 } | |
| 6280 } | |
| 6281 | |
| 6282 | |
| 6283 // Test that GetEventContext doesn't fail and return empty handle for | |
| 6284 // ScriptCollected events. | |
| 6285 TEST(ScriptCollectedEventContext) { | |
| 6286 i::FLAG_stress_compaction = false; | |
| 6287 v8::Isolate* isolate = CcTest::isolate(); | |
| 6288 v8::internal::Debug* debug = | |
| 6289 reinterpret_cast<v8::internal::Isolate*>(isolate)->debug(); | |
| 6290 script_collected_message_count = 0; | |
| 6291 v8::HandleScope scope(isolate); | |
| 6292 | |
| 6293 v8::Persistent<v8::Context> context; | |
| 6294 { | |
| 6295 v8::HandleScope scope(isolate); | |
| 6296 context.Reset(isolate, v8::Context::New(isolate)); | |
| 6297 } | |
| 6298 | |
| 6299 // Enter context. We can't have a handle to the context in the outer | |
| 6300 // scope, so we have to do it the hard way. | |
| 6301 { | |
| 6302 v8::HandleScope scope(isolate); | |
| 6303 v8::Local<v8::Context> local_context = | |
| 6304 v8::Local<v8::Context>::New(isolate, context); | |
| 6305 local_context->Enter(); | |
| 6306 } | |
| 6307 | |
| 6308 // Request the loaded scripts to initialize the debugger script cache. | |
| 6309 debug->GetLoadedScripts(); | |
| 6310 | |
| 6311 // Do garbage collection to ensure that only the script in this test will be | |
| 6312 // collected afterwards. | |
| 6313 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 6314 | |
| 6315 v8::Debug::SetMessageHandler(ScriptCollectedMessageHandler); | |
| 6316 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=1')"))->Run(); | |
| 6317 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "eval('a=2')"))->Run(); | |
| 6318 | |
| 6319 // Leave context | |
| 6320 { | |
| 6321 v8::HandleScope scope(isolate); | |
| 6322 v8::Local<v8::Context> local_context = | |
| 6323 v8::Local<v8::Context>::New(isolate, context); | |
| 6324 local_context->Exit(); | |
| 6325 } | |
| 6326 context.Reset(); | |
| 6327 | |
| 6328 // Do garbage collection to collect the script above which is no longer | |
| 6329 // referenced. | |
| 6330 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | |
| 6331 | |
| 6332 CHECK_EQ(2, script_collected_message_count); | |
| 6333 | |
| 6334 v8::Debug::SetMessageHandler(NULL); | |
| 6335 } | |
| 6336 | |
| 6337 | |
| 6338 // Debug event listener which counts the after compile events. | 6224 // Debug event listener which counts the after compile events. |
| 6339 int after_compile_message_count = 0; | 6225 int after_compile_message_count = 0; |
| 6340 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { | 6226 static void AfterCompileMessageHandler(const v8::Debug::Message& message) { |
| 6341 // Count the number of scripts collected. | 6227 // Count the number of scripts collected. |
| 6342 if (message.IsEvent()) { | 6228 if (message.IsEvent()) { |
| 6343 if (message.GetEvent() == v8::AfterCompile) { | 6229 if (message.GetEvent() == v8::AfterCompile) { |
| 6344 after_compile_message_count++; | 6230 after_compile_message_count++; |
| 6345 } else if (message.GetEvent() == v8::Break) { | 6231 } else if (message.GetEvent() == v8::Break) { |
| 6346 SendContinueCommand(); | 6232 SendContinueCommand(); |
| 6347 } | 6233 } |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7522 TEST(DebugBreakOffThreadTerminate) { | 7408 TEST(DebugBreakOffThreadTerminate) { |
| 7523 DebugLocalContext env; | 7409 DebugLocalContext env; |
| 7524 v8::Isolate* isolate = env->GetIsolate(); | 7410 v8::Isolate* isolate = env->GetIsolate(); |
| 7525 v8::HandleScope scope(isolate); | 7411 v8::HandleScope scope(isolate); |
| 7526 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); | 7412 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); |
| 7527 TerminationThread terminator(isolate); | 7413 TerminationThread terminator(isolate); |
| 7528 terminator.Start(); | 7414 terminator.Start(); |
| 7529 v8::Debug::DebugBreak(isolate); | 7415 v8::Debug::DebugBreak(isolate); |
| 7530 CompileRun("while (true);"); | 7416 CompileRun("while (true);"); |
| 7531 } | 7417 } |
| OLD | NEW |