Fixed bug that caused function literals to not be optimized as much as other functions.

Improved profiler support.

Fixed a crash bug in connection with debugger unloading.

Fixed a crash bug in the code generator caused by losing the information that a frame element was copied.

Fixed an exception propagation bug that could cause non-null return values when exceptions were thrown.



git-svn-id: http://v8.googlecode.com/svn/trunk@1664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc
index 81b5144..74d590e 100644
--- a/test/cctest/test-debug.cc
+++ b/test/cctest/test-debug.cc
@@ -390,12 +390,6 @@
 }
 
 
-// Check that the debugger is loaded.
-static void CheckDebuggerLoaded() {
-  CHECK(Debug::debug_context().is_null());
-}
-
-
 // Check that the debugger has been fully unloaded.
 void CheckDebuggerUnloaded(bool check_functions) {
   // Check that the debugger context is cleared and that there is no debug
@@ -437,12 +431,6 @@
 } }  // namespace v8::internal
 
 
-// Check that the debugger is loaded.
-static void CheckDebuggerLoaded() {
-  v8::internal::CheckDebuggerLoaded();
-}
-
-
 // Check that the debugger has been fully unloaded.
 static void CheckDebuggerUnloaded(bool check_functions = false) {
   v8::internal::CheckDebuggerUnloaded(check_functions);
@@ -3740,8 +3728,6 @@
   // Add debug event listener.
   v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
                                    v8::Undefined());
-  CheckDebuggerLoaded();
-
   // Create a couple of functions for the test.
   v8::Local<v8::Function> foo =
       CompileFunction(&env, "function foo(){x=1}", "foo");
@@ -3768,8 +3754,6 @@
   // Set a new debug event listener.
   v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount,
                                    v8::Undefined());
-  CheckDebuggerLoaded();
-
   // Check that the break points was actually cleared.
   break_point_hit_count = 0;
   foo->Call(env->Global(), 0, NULL);
@@ -3787,6 +3771,89 @@
 }
 
 
+// Debugger message handler which counts the number of times it is called.
+static int message_handler_hit_count = 0;
+static void MessageHandlerHitCount(const uint16_t* message,
+                                   int length, void* data) {
+  message_handler_hit_count++;
+
+  const int kBufferSize = 1000;
+  uint16_t buffer[kBufferSize];
+  const char* command_continue =
+    "{\"seq\":0,"
+     "\"type\":\"request\","
+     "\"command\":\"continue\"}";
+
+  v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
+}
+
+
+// Test clearing the debug message handler.
+TEST(DebuggerClearMessageHandler) {
+  v8::HandleScope scope;
+  DebugLocalContext env;
+
+  // Check debugger is unloaded before it is used.
+  CheckDebuggerUnloaded();
+
+  // Set a debug message handler.
+  v8::Debug::SetMessageHandler(MessageHandlerHitCount);
+
+  // Run code to throw a unhandled exception. This should end up in the message
+  // handler.
+  CompileRun("throw 1");
+
+  // The message handler should be called.
+  CHECK_GT(message_handler_hit_count, 0);
+
+  // Clear debug message handler.
+  message_handler_hit_count = 0;
+  v8::Debug::SetMessageHandler(NULL);
+
+  // Run code to throw a unhandled exception. This should end up in the message
+  // handler.
+  CompileRun("throw 1");
+
+  // The message handler should not be called more.
+  CHECK_EQ(0, message_handler_hit_count);
+
+  CheckDebuggerUnloaded(true);
+}
+
+
+// Debugger message handler which clears the message handler while active.
+static void MessageHandlerClearingMessageHandler(const uint16_t* message,
+                                                 int length,
+                                                 void* data) {
+  message_handler_hit_count++;
+
+  // Clear debug message handler.
+  v8::Debug::SetMessageHandler(NULL);
+}
+
+
+// Test clearing the debug message handler while processing a debug event.
+TEST(DebuggerClearMessageHandlerWhileActive) {
+  v8::HandleScope scope;
+  DebugLocalContext env;
+
+  // Check debugger is unloaded before it is used.
+  CheckDebuggerUnloaded();
+
+  // Set a debug message handler.
+  v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler);
+
+  // Run code to throw a unhandled exception. This should end up in the message
+  // handler.
+  CompileRun("throw 1");
+
+  // The message handler should be called.
+  CHECK_EQ(1, message_handler_hit_count);
+
+  CheckDebuggerUnloaded(true);
+}
+
+
 int host_dispatch_hit_count = 0;
 static void HostDispatchHandlerHitCount(void* dispatch, void *data) {
   host_dispatch_hit_count++;