Added some missing initialization checks to the debugger API.
authorsgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 30 Oct 2008 10:27:28 +0000 (10:27 +0000)
committersgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 30 Oct 2008 10:27:28 +0000 (10:27 +0000)
BUG=3723 (Chromium)
Review URL: http://codereview.chromium.org/8909

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@648 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/api.cc
test/cctest/test-debug.cc

index cdf0ed6d19da49949f15faded7193fab9bdc42c1..f17be017835d542a8925801b54224fd86eb3af09 100644 (file)
@@ -2800,8 +2800,8 @@ Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) {
 
 
 bool Debug::AddDebugEventListener(DebugEventCallback that, Handle<Value> data) {
-  EnsureInitialized("v8::V8::AddDebugEventListener()");
-  ON_BAILOUT("v8::V8::AddDebugEventListener()", return false);
+  EnsureInitialized("v8::Debug::AddDebugEventListener()");
+  ON_BAILOUT("v8::Debug::AddDebugEventListener()", return false);
   HandleScope scope;
   NeanderArray listeners(i::Factory::debug_event_listeners());
   NeanderObject obj(2);
@@ -2817,7 +2817,7 @@ bool Debug::AddDebugEventListener(DebugEventCallback that, Handle<Value> data) {
 
 bool Debug::AddDebugEventListener(v8::Handle<v8::Function> that,
                                   Handle<Value> data) {
-  ON_BAILOUT("v8::V8::AddDebugEventListener()", return false);
+  ON_BAILOUT("v8::Debug::AddDebugEventListener()", return false);
   HandleScope scope;
   NeanderArray listeners(i::Factory::debug_event_listeners());
   NeanderObject obj(2);
@@ -2832,8 +2832,8 @@ bool Debug::AddDebugEventListener(v8::Handle<v8::Function> that,
 
 
 void Debug::RemoveDebugEventListener(DebugEventCallback that) {
-  EnsureInitialized("v8::V8::RemoveDebugEventListener()");
-  ON_BAILOUT("v8::V8::RemoveDebugEventListener()", return);
+  EnsureInitialized("v8::Debug::RemoveDebugEventListener()");
+  ON_BAILOUT("v8::Debug::RemoveDebugEventListener()", return);
   HandleScope scope;
   NeanderArray listeners(i::Factory::debug_event_listeners());
   for (int i = 0; i < listeners.length(); i++) {
@@ -2853,7 +2853,7 @@ void Debug::RemoveDebugEventListener(DebugEventCallback that) {
 
 
 void Debug::RemoveDebugEventListener(v8::Handle<v8::Function> that) {
-  ON_BAILOUT("v8::V8::RemoveDebugEventListener()", return);
+  ON_BAILOUT("v8::Debug::RemoveDebugEventListener()", return);
   HandleScope scope;
   NeanderArray listeners(i::Factory::debug_event_listeners());
   for (int i = 0; i < listeners.length(); i++) {
@@ -2875,16 +2875,19 @@ void Debug::RemoveDebugEventListener(v8::Handle<v8::Function> that) {
 
 
 void Debug::DebugBreak() {
+  if (!i::V8::HasBeenSetup()) return;
   i::StackGuard::DebugBreak();
 }
 
 
 void Debug::SetMessageHandler(v8::DebugMessageHandler handler, void* data) {
+  EnsureInitialized("v8::Debug::SetMessageHandler");
   i::Debugger::SetMessageHandler(handler, data);
 }
 
 
 void Debug::SendCommand(const uint16_t* command, int length) {
+  if (!i::V8::HasBeenSetup()) return;
   i::Debugger::ProcessCommand(i::Vector<const uint16_t>(command, length));
 }
 
index 2ad3347fbba8f501612e95b9251474e4a1ac5ec2..ea819e0dac5b501435837c382a11b482e86ad698 100644 (file)
@@ -3131,3 +3131,38 @@ TEST(RecursiveBreakpoints) {
   breakpoints_v8_thread.Join();
   breakpoints_debugger_thread.Join();
 }
+
+
+static void DummyDebugEventListener(v8::DebugEvent event,
+                                    v8::Handle<v8::Object> exec_state,
+                                    v8::Handle<v8::Object> event_data,
+                                    v8::Handle<v8::Value> data) {
+}
+
+
+TEST(AddDebugEventListenerOnUninitializedVM) {
+  v8::Debug::AddDebugEventListener(DummyDebugEventListener);
+}
+
+
+static void DummyMessageHandler(const uint16_t* message,
+                                int length, void *data) {
+}
+
+
+TEST(SetMessageHandlerOnUninitializedVM) {
+  v8::Debug::SetMessageHandler(DummyMessageHandler);
+}
+
+
+TEST(DebugBreakOnUninitializedVM) {
+  v8::Debug::DebugBreak();
+}
+
+
+TEST(SendCommandToUninitializedVM) {
+  const char* dummy_command = "{}";
+  uint16_t dummy_buffer[80];
+  int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer);
+  v8::Debug::SendCommand(dummy_buffer, dummy_length);
+}