Commit 2beedf11 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Create a transition API for the debug message handler.

Kept the previous message handler API to avoid breaking clients depending on it.

The new message handler API uses a new name ending with 2.
Review URL: http://codereview.chromium.org/100158

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1816 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 37036ff4
......@@ -162,12 +162,25 @@ class EXPORT Debug {
*
* \param message the debug message handler message object
* \param length length of the message
* \param data the data value passed when registering the message handler
* \param client_data the data value passed when registering the message handler
* A MessageHandler does not take posession of the message string,
* and must not rely on the data persisting after the handler returns.
*
* This message handler is deprecated. Use MessageHandler2 instead.
*/
typedef void (*MessageHandler)(const uint16_t* message, int length,
ClientData* client_data);
/**
* Debug message callback function.
*
* \param message the debug message handler message object
* A MessageHandler does not take posession of the message data,
* and must not rely on the data persisting after the handler returns.
*/
typedef void (*MessageHandler)(const Message& message);
typedef void (*MessageHandler2)(const Message& message);
/**
* Debug host dispatch callback function.
......@@ -189,6 +202,7 @@ class EXPORT Debug {
// handler thread is not supported any more parameter must be false.
static void SetMessageHandler(MessageHandler handler,
bool message_handler_thread = false);
static void SetMessageHandler2(MessageHandler2 handler);
static void SendCommand(const uint16_t* command, int length,
ClientData* client_data = NULL);
......
......@@ -3260,6 +3260,16 @@ void Debug::DebugBreak() {
}
static v8::Debug::MessageHandler message_handler = NULL;
static void MessageHandlerWrapper(const v8::Debug::Message& message) {
if (message_handler) {
v8::String::Value json(message.GetJSON());
message_handler(*json, json.length(), message.GetClientData());
}
}
void Debug::SetMessageHandler(v8::Debug::MessageHandler handler,
bool message_handler_thread) {
EnsureInitialized("v8::Debug::SetMessageHandler");
......@@ -3267,6 +3277,20 @@ void Debug::SetMessageHandler(v8::Debug::MessageHandler handler,
// Message handler thread not supported any more. Parameter temporally left in
// the API for client compatability reasons.
CHECK(!message_handler_thread);
// TODO(sgjesse) support the old message handler API through a simple wrapper.
message_handler = handler;
if (message_handler != NULL) {
i::Debugger::SetMessageHandler(MessageHandlerWrapper);
} else {
i::Debugger::SetMessageHandler(NULL);
}
}
void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) {
EnsureInitialized("v8::Debug::SetMessageHandler");
ENTER_V8;
i::Debugger::SetMessageHandler(handler);
}
......
......@@ -106,7 +106,7 @@ void DebuggerAgent::CreateSession(Socket* client) {
// Create a new session and hook up the debug message handler.
session_ = new DebuggerAgentSession(this, client);
v8::Debug::SetMessageHandler(DebuggerAgentMessageHandler);
v8::Debug::SetMessageHandler2(DebuggerAgentMessageHandler);
session_->Start();
}
......
......@@ -1420,7 +1420,7 @@ Handle<Object> Debugger::event_listener_data_ = Handle<Object>();
bool Debugger::compiling_natives_ = false;
bool Debugger::is_loading_debugger_ = false;
bool Debugger::never_unload_debugger_ = false;
v8::Debug::MessageHandler Debugger::message_handler_ = NULL;
v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL;
bool Debugger::message_handler_cleared_ = false;
v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL;
int Debugger::host_dispatch_micros_ = 100 * 1000;
......@@ -1963,7 +1963,7 @@ void Debugger::SetEventListener(Handle<Object> callback,
}
void Debugger::SetMessageHandler(v8::Debug::MessageHandler handler) {
void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
ScopedLock with(debugger_access_);
message_handler_ = handler;
......
......@@ -546,7 +546,7 @@ class Debugger {
Handle<JSObject> event_data,
bool auto_continue);
static void SetEventListener(Handle<Object> callback, Handle<Object> data);
static void SetMessageHandler(v8::Debug::MessageHandler handler);
static void SetMessageHandler(v8::Debug::MessageHandler2 handler);
static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
int period);
......@@ -602,7 +602,7 @@ class Debugger {
static bool compiling_natives_; // Are we compiling natives?
static bool is_loading_debugger_; // Are we loading the debugger?
static bool never_unload_debugger_; // Can we unload the debugger?
static v8::Debug::MessageHandler message_handler_;
static v8::Debug::MessageHandler2 message_handler_;
static bool message_handler_cleared_; // Was message handler cleared?
static v8::Debug::HostDispatchHandler host_dispatch_handler_;
static int host_dispatch_micros_;
......
......@@ -3427,10 +3427,10 @@ class MessageQueueDebuggerThread : public v8::internal::Thread {
void Run();
};
static void MessageHandler(const v8::Debug::Message& message) {
static void MessageHandler(const uint16_t* message, int length,
v8::Debug::ClientData* client_data) {
static char print_buffer[1000];
v8::String::Value json(message.GetJSON());
Utf16ToAscii(*json, json.length(), print_buffer);
Utf16ToAscii(message, length, print_buffer);
if (IsBreakEventMessage(print_buffer)) {
// Lets test script wait until break occurs to send commands.
// Signals when a break is reported.
......@@ -3626,7 +3626,7 @@ TEST(SendClientDataToHandler) {
DebugLocalContext env;
TestClientData::ResetCounters();
handled_client_data_instances_count = 0;
v8::Debug::SetMessageHandler(MessageHandlerCountingClientData);
v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
const int kBufferSize = 1000;
uint16_t buffer[kBufferSize];
......@@ -3723,7 +3723,7 @@ void V8Thread::Run() {
v8::HandleScope scope;
DebugLocalContext env;
v8::Debug::SetMessageHandler(&ThreadedMessageHandler);
v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
global_template->Set(v8::String::New("ThreadedAtBarrier1"),
v8::FunctionTemplate::New(ThreadedAtBarrier1));
......@@ -3823,7 +3823,7 @@ void BreakpointsV8Thread::Run() {
v8::HandleScope scope;
DebugLocalContext env;
v8::Debug::SetMessageHandler(&BreakpointsMessageHandler);
v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
CompileRun(source_1);
breakpoints_barriers->barrier_1.Wait();
......@@ -3937,7 +3937,7 @@ static void DummyMessageHandler(const v8::Debug::Message& message) {
TEST(SetMessageHandlerOnUninitializedVM) {
v8::Debug::SetMessageHandler(DummyMessageHandler);
v8::Debug::SetMessageHandler2(DummyMessageHandler);
}
......@@ -4180,7 +4180,7 @@ TEST(DebuggerClearMessageHandler) {
CheckDebuggerUnloaded();
// Set a debug message handler.
v8::Debug::SetMessageHandler(MessageHandlerHitCount);
v8::Debug::SetMessageHandler2(MessageHandlerHitCount);
// Run code to throw a unhandled exception. This should end up in the message
// handler.
......@@ -4223,7 +4223,7 @@ TEST(DebuggerClearMessageHandlerWhileActive) {
CheckDebuggerUnloaded();
// Set a debug message handler.
v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler);
v8::Debug::SetMessageHandler2(MessageHandlerClearingMessageHandler);
// Run code to throw a unhandled exception. This should end up in the message
// handler.
......@@ -4283,7 +4283,7 @@ void HostDispatchV8Thread::Run() {
DebugLocalContext env;
// Setup message and host dispatch handlers.
v8::Debug::SetMessageHandler(HostDispatchMessageHandler);
v8::Debug::SetMessageHandler2(HostDispatchMessageHandler);
v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
CompileRun(source_1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment