コード例 #1
0
void DebuggerAgentManager::onV8DebugMessage(const v8::Debug::Message& message)
{
    v8::HandleScope scope;
    v8::String::Value value(message.GetJSON());
    WTF::String out(reinterpret_cast<const UChar*>(*value), value.length());

    // If callerData is not 0 the message is a response to a debugger command.
    if (v8::Debug::ClientData* callerData = message.GetClientData()) {
        CallerIdWrapper* wrapper = static_cast<CallerIdWrapper*>(callerData);
        if (wrapper->callerIsMananager()) {
            // Just ignore messages sent by this manager.
            return;
        }
        DebuggerAgentImpl* debuggerAgent = debuggerAgentForHostId(wrapper->callerId());
        if (debuggerAgent)
            debuggerAgent->debuggerOutput(out);
        else if (!message.WillStartRunning()) {
            // Autocontinue execution if there is no handler.
            sendContinueCommandToV8();
        }
        return;
    } // Otherwise it's an event message.
    ASSERT(message.IsEvent());

    // Ignore unsupported event types.
    if (message.GetEvent() != v8::AfterCompile && message.GetEvent() != v8::Break && message.GetEvent() != v8::Exception)
        return;

    v8::Handle<v8::Context> context = message.GetEventContext();
    // If the context is from one of the inpected tabs it should have its context
    // data.
    if (context.IsEmpty()) {
        // Unknown context, skip the event.
        return;
    }

    // If the context is from one of the inpected tabs or injected extension
    // scripts it must have hostId in the data field.
    int hostId = WebCore::V8Proxy::contextDebugId(context);
    if (hostId != -1) {
        DebuggerAgentImpl* agent = debuggerAgentForHostId(hostId);
        if (agent) {
            if (agent->autoContinueOnException()
                && message.GetEvent() == v8::Exception) {
                sendContinueCommandToV8();
                return;
            }

            agent->debuggerOutput(out);
            return;
        }
    }

    if (!message.WillStartRunning()) {
        // Autocontinue execution on break and exception  events if there is no
        // handler.
        sendContinueCommandToV8();
    }
}
コード例 #2
0
/* *
 * private method that takes debug message as json from v8
 * after it gets the message the message handler passes it to enqueueMessage method in java
 */
void JsDebugger::MyMessageHandler(const v8::Debug::Message& message)
{
	if (s_jsDebugger == nullptr)
	{
		return;
	}

	auto json = message.GetJSON();
	auto str = ConvertToString(json);

	JEnv env;
	JniLocalRef s(env.NewStringUTF(str.c_str()));
	env.CallVoidMethod(s_jsDebugger, s_EnqueueMessage, (jstring) s);
}
コード例 #3
0
void JSDebugger::MessageHandler(const v8::Debug::Message& message)
{
	if (debugger__ == nullptr)
	{
		return;
	}

	JNIEnv *env = JNIUtil::getJNIEnv();
	ASSERT(env != NULL);

	auto json = message.GetJSON();
	jstring s = TypeConverter::jsStringToJavaString(env, json);
	env->CallVoidMethod(debugger__, handleMessage__, s);
	env->DeleteLocalRef(s);
}
コード例 #4
0
void ScriptDebugServer::handleV8DebugMessage(const v8::Debug::Message& message)
{
    v8::HandleScope scope;

    if (!message.IsEvent())
        return;

    // Ignore unsupported event types.
    if (message.GetEvent() != v8::AfterCompile && message.GetEvent() != v8::Break && message.GetEvent() != v8::Exception)
        return;

    v8::Handle<v8::Context> context = message.GetEventContext();
    // If the context is from one of the inpected tabs it should have its context
    // data. Skip events from unknown contexts.
    if (context.IsEmpty())
        return;

    // Test that context has associated global dom window object.
    v8::Handle<v8::Object> global = context->Global();
    if (global.IsEmpty())
        return;

    global = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global);
    if (global.IsEmpty())
        return;

    bool handled = false;
    Frame* frame = V8Proxy::retrieveFrame(context);
    if (frame) {
        ScriptDebugListener* listener = m_listenersMap.get(frame->page());
        if (listener) {
            if (message.GetEvent() == v8::AfterCompile) {
                handled = true;
                v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
                v8::Local<v8::Object> args = v8::Object::New();
                args->Set(v8::String::New("eventData"), message.GetEventData());
                v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getAfterCompileScript")));
                v8::Handle<v8::Value> argv[] = { message.GetExecutionState(), args };
                v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debuggerScript.get(), 2, argv);
                ASSERT(value->IsObject());
                v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
                dispatchDidParseSource(listener, object);
            } else if (message.GetEvent() == v8::Break || message.GetEvent() == v8::Exception) {
                handled = true;
                m_executionState.set(message.GetExecutionState());
                m_currentCallFrameState = mainWorldScriptState(frame);
                listener->didPause();
                m_currentCallFrameState = 0;
            }
        }
    }

    if (!handled && !message.WillStartRunning())
        continueProgram();
}