From: sgjesse@chromium.org Date: Wed, 17 Jun 2009 13:14:51 +0000 (+0000) Subject: Fix unload debugger. X-Git-Tag: upstream/4.7.83~23875 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f36c8574c9337503359f665bf15175a59f49bb6d;p=platform%2Fupstream%2Fv8.git Fix unload debugger. Add a missing handle scope when clearing the debug message handler. BUG=none TEST=cctest/test-debug/DebuggerUnload Review URL: http://codereview.chromium.org/126271 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2206 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/api.cc b/src/api.cc index 097c2ea68..100184790 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3384,6 +3384,7 @@ void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { EnsureInitialized("v8::Debug::SetMessageHandler"); ENTER_V8; + HandleScope scope; i::Debugger::SetMessageHandler(handler); } diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index 7669b4327..342994e98 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -4235,57 +4235,83 @@ TEST(CallFunctionInDebugger) { } +// Debugger message handler which counts the number of breaks. +static void SendContinueCommand(); +static void MessageHandlerBreakPointHitCount( + const v8::Debug::Message& message) { + if (message.IsEvent() && message.GetEvent() == v8::Break) { + // Count the number of breaks. + break_point_hit_count++; + + SendContinueCommand(); + } +} + + // Test that clearing the debug event listener actually clears all break points // and related information. TEST(DebuggerUnload) { - v8::HandleScope scope; DebugLocalContext env; // Check debugger is unloaded before it is used. CheckDebuggerUnloaded(); - // Add debug event listener. + // Set a debug event listener. + break_point_hit_count = 0; v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, v8::Undefined()); - // Create a couple of functions for the test. - v8::Local foo = - CompileFunction(&env, "function foo(){x=1}", "foo"); - v8::Local bar = - CompileFunction(&env, "function bar(){y=2}", "bar"); - - // Set some break points. - SetBreakPoint(foo, 0); - SetBreakPoint(foo, 4); - SetBreakPoint(bar, 0); - SetBreakPoint(bar, 4); - - // Make sure that the break points are there. - break_point_hit_count = 0; - foo->Call(env->Global(), 0, NULL); - CHECK_EQ(2, break_point_hit_count); - bar->Call(env->Global(), 0, NULL); - CHECK_EQ(4, break_point_hit_count); - - // Remove the debug event listener without clearing breakpoints. + { + v8::HandleScope scope; + // Create a couple of functions for the test. + v8::Local foo = + CompileFunction(&env, "function foo(){x=1}", "foo"); + v8::Local bar = + CompileFunction(&env, "function bar(){y=2}", "bar"); + + // Set some break points. + SetBreakPoint(foo, 0); + SetBreakPoint(foo, 4); + SetBreakPoint(bar, 0); + SetBreakPoint(bar, 4); + + // Make sure that the break points are there. + break_point_hit_count = 0; + foo->Call(env->Global(), 0, NULL); + CHECK_EQ(2, break_point_hit_count); + bar->Call(env->Global(), 0, NULL); + CHECK_EQ(4, break_point_hit_count); + } + + // Remove the debug event listener without clearing breakpoints. Do this + // outside a handle scope. v8::Debug::SetDebugEventListener(NULL); CheckDebuggerUnloaded(true); - // Set a new debug event listener. - v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, - v8::Undefined()); - // Check that the break points was actually cleared. + // Now set a debug message handler. break_point_hit_count = 0; - foo->Call(env->Global(), 0, NULL); - CHECK_EQ(0, break_point_hit_count); + v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); + { + v8::HandleScope scope; - // Set break points and run again. - SetBreakPoint(foo, 0); - SetBreakPoint(foo, 4); - foo->Call(env->Global(), 0, NULL); - CHECK_EQ(2, break_point_hit_count); + // Get the test functions again. + v8::Local foo = + v8::Local::Cast(env->Global()->Get(v8::String::New("foo"))); + v8::Local bar = + v8::Local::Cast(env->Global()->Get(v8::String::New("foo"))); - // Remove the debug event listener without clearing breakpoints again. - v8::Debug::SetDebugEventListener(NULL); + foo->Call(env->Global(), 0, NULL); + CHECK_EQ(0, break_point_hit_count); + + // Set break points and run again. + SetBreakPoint(foo, 0); + SetBreakPoint(foo, 4); + foo->Call(env->Global(), 0, NULL); + CHECK_EQ(2, break_point_hit_count); + } + + // Remove the debug message handler without clearing breakpoints. Do this + // outside a handle scope. + v8::Debug::SetMessageHandler2(NULL); CheckDebuggerUnloaded(true); }