Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: test/cctest/test-debug.cc

Issue 126271: Fix unload debugger (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 v8::Integer::New(7)); 4228 v8::Integer::New(7));
4229 v8::Script::Compile(v8::String::New("CheckSourceLine(7)"), &origin)->Run(); 4229 v8::Script::Compile(v8::String::New("CheckSourceLine(7)"), &origin)->Run();
4230 v8::Script::Compile(v8::String::New("function f() {\n" 4230 v8::Script::Compile(v8::String::New("function f() {\n"
4231 " CheckSourceLine(8)\n" 4231 " CheckSourceLine(8)\n"
4232 " CheckSourceLine(9)\n" 4232 " CheckSourceLine(9)\n"
4233 " CheckSourceLine(10)\n" 4233 " CheckSourceLine(10)\n"
4234 "}; f()"), &origin)->Run(); 4234 "}; f()"), &origin)->Run();
4235 } 4235 }
4236 4236
4237 4237
4238 // Debugger message handler which counts the number of breaks.
4239 static void SendContinueCommand();
4240 static void MessageHandlerBreakPointHitCount(
4241 const v8::Debug::Message& message) {
4242 if (message.IsEvent() && message.GetEvent() == v8::Break) {
4243 // Count the number of breaks.
4244 break_point_hit_count++;
4245
4246 SendContinueCommand();
4247 }
4248 }
4249
4250
4238 // Test that clearing the debug event listener actually clears all break points 4251 // Test that clearing the debug event listener actually clears all break points
4239 // and related information. 4252 // and related information.
4240 TEST(DebuggerUnload) { 4253 TEST(DebuggerUnload) {
4241 v8::HandleScope scope;
4242 DebugLocalContext env; 4254 DebugLocalContext env;
4243 4255
4244 // Check debugger is unloaded before it is used. 4256 // Check debugger is unloaded before it is used.
4245 CheckDebuggerUnloaded(); 4257 CheckDebuggerUnloaded();
4246 4258
4247 // Add debug event listener. 4259 // Set a debug event listener.
4260 break_point_hit_count = 0;
4248 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, 4261 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
4249 v8::Undefined()); 4262 v8::Undefined());
4250 // Create a couple of functions for the test. 4263 {
4251 v8::Local<v8::Function> foo = 4264 v8::HandleScope scope;
4252 CompileFunction(&env, "function foo(){x=1}", "foo"); 4265 // Create a couple of functions for the test.
4253 v8::Local<v8::Function> bar = 4266 v8::Local<v8::Function> foo =
4254 CompileFunction(&env, "function bar(){y=2}", "bar"); 4267 CompileFunction(&env, "function foo(){x=1}", "foo");
4268 v8::Local<v8::Function> bar =
4269 CompileFunction(&env, "function bar(){y=2}", "bar");
4255 4270
4256 // Set some break points. 4271 // Set some break points.
4257 SetBreakPoint(foo, 0); 4272 SetBreakPoint(foo, 0);
4258 SetBreakPoint(foo, 4); 4273 SetBreakPoint(foo, 4);
4259 SetBreakPoint(bar, 0); 4274 SetBreakPoint(bar, 0);
4260 SetBreakPoint(bar, 4); 4275 SetBreakPoint(bar, 4);
4261 4276
4262 // Make sure that the break points are there. 4277 // Make sure that the break points are there.
4263 break_point_hit_count = 0; 4278 break_point_hit_count = 0;
4264 foo->Call(env->Global(), 0, NULL); 4279 foo->Call(env->Global(), 0, NULL);
4265 CHECK_EQ(2, break_point_hit_count); 4280 CHECK_EQ(2, break_point_hit_count);
4266 bar->Call(env->Global(), 0, NULL); 4281 bar->Call(env->Global(), 0, NULL);
4267 CHECK_EQ(4, break_point_hit_count); 4282 CHECK_EQ(4, break_point_hit_count);
4268 4283 }
4269 // Remove the debug event listener without clearing breakpoints. 4284
4285 // Remove the debug event listener without clearing breakpoints. Do this
4286 // outside a handle scope.
4270 v8::Debug::SetDebugEventListener(NULL); 4287 v8::Debug::SetDebugEventListener(NULL);
4271 CheckDebuggerUnloaded(true); 4288 CheckDebuggerUnloaded(true);
4272 4289
4273 // Set a new debug event listener. 4290 // Now set a debug message handler.
4274 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
4275 v8::Undefined());
4276 // Check that the break points was actually cleared.
4277 break_point_hit_count = 0; 4291 break_point_hit_count = 0;
4278 foo->Call(env->Global(), 0, NULL); 4292 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount);
4279 CHECK_EQ(0, break_point_hit_count); 4293 {
4294 v8::HandleScope scope;
4280 4295
4281 // Set break points and run again. 4296 // Get the test functions again.
4282 SetBreakPoint(foo, 0); 4297 v8::Local<v8::Function> foo =
4283 SetBreakPoint(foo, 4); 4298 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
4284 foo->Call(env->Global(), 0, NULL); 4299 v8::Local<v8::Function> bar =
4285 CHECK_EQ(2, break_point_hit_count); 4300 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));
4286 4301
4287 // Remove the debug event listener without clearing breakpoints again. 4302 foo->Call(env->Global(), 0, NULL);
4288 v8::Debug::SetDebugEventListener(NULL); 4303 CHECK_EQ(0, break_point_hit_count);
4304
4305 // Set break points and run again.
4306 SetBreakPoint(foo, 0);
4307 SetBreakPoint(foo, 4);
4308 foo->Call(env->Global(), 0, NULL);
4309 CHECK_EQ(2, break_point_hit_count);
4310 }
4311
4312 // Remove the debug message handler without clearing breakpoints. Do this
4313 // outside a handle scope.
4314 v8::Debug::SetMessageHandler2(NULL);
4289 CheckDebuggerUnloaded(true); 4315 CheckDebuggerUnloaded(true);
4290 } 4316 }
4291 4317
4292 4318
4293 // Sends continue command to the debugger. 4319 // Sends continue command to the debugger.
4294 static void SendContinueCommand() { 4320 static void SendContinueCommand() {
4295 const int kBufferSize = 1000; 4321 const int kBufferSize = 1000;
4296 uint16_t buffer[kBufferSize]; 4322 uint16_t buffer[kBufferSize];
4297 const char* command_continue = 4323 const char* command_continue =
4298 "{\"seq\":0," 4324 "{\"seq\":0,"
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 v8::Local<v8::Function> f = 5250 v8::Local<v8::Function> f =
5225 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 5251 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
5226 f->Call(env->Global(), 0, NULL); 5252 f->Call(env->Global(), 0, NULL);
5227 5253
5228 // Setting message handler to NULL should cause debugger unload. 5254 // Setting message handler to NULL should cause debugger unload.
5229 v8::Debug::SetMessageHandler2(NULL); 5255 v8::Debug::SetMessageHandler2(NULL);
5230 CheckDebuggerUnloaded(); 5256 CheckDebuggerUnloaded();
5231 5257
5232 CHECK_EQ(1, exception_event_count); 5258 CHECK_EQ(1, exception_event_count);
5233 } 5259 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698