Added some missing initialization checks to the debugger API.

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
This commit is contained in:
sgjesse@chromium.org 2008-10-30 10:27:28 +00:00
parent a2be3b6f84
commit 52b2a12684
2 changed files with 44 additions and 6 deletions

View 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));
}

View 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);
}